• 经典多线程问题(五)-按顺序执行的问题


    package com.example.demo;
    
    import java.util.concurrent.CountDownLatch;
    
    /**
     * @ClassName Foo
     * @Description: 1114. 按序打印(多线程)
     * @Author xtanb
     * @Date 2019/9/23
     * @Version V1.0
     **/
    public class Foo {
        private CountDownLatch countDownLatchA;
        private CountDownLatch countDownLatchB;
    
        public Foo() {
            this.countDownLatchA = new CountDownLatch(1);
            this.countDownLatchB = new CountDownLatch(1);
        }
    
        public void first(Runnable printFirst) throws InterruptedException {
    
            // printFirst.run() outputs "first". Do not change or remove this line.
            printFirst.run();
            countDownLatchA.countDown();
        }
    
        public void second(Runnable printSecond) throws InterruptedException {
            countDownLatchA.await();
            // printSecond.run() outputs "second". Do not change or remove this line.
            printSecond.run();
            countDownLatchB.countDown();
        }
    
        public void third(Runnable printThird) throws InterruptedException {
            countDownLatchB.await();
            // printThird.run() outputs "third". Do not change or remove this line.
            printThird.run();
        }
    }
  • 相关阅读:
    ORACLE AWR 和 ASH
    11g RAC R2 日常巡检--Grid
    Linux中重命名文件
    Xshell4连接Linux后 win快捷键锁屏
    vim 删除临时文件
    shell--read命令
    shell基础篇(一)从hello world开始
    ORACLE--分区表数据清理
    Shell—学习之心得
    awk 手册--【转载】
  • 原文地址:https://www.cnblogs.com/helloworldmybokeyuan/p/11718501.html
Copyright © 2020-2023  润新知