美文网首页
1114. 按序打印

1114. 按序打印

作者: 上杉丶零 | 来源:发表于2020-03-19 13:45 被阅读0次
class Foo {
    private CountDownLatch second;
    private CountDownLatch third;

    public Foo() {
        second = new CountDownLatch(1);
        third = new CountDownLatch(1);
    }

    public void first(Runnable printFirst) throws InterruptedException {
        // printFirst.run() outputs "first". Do not change or remove this line.
        printFirst.run();
        second.countDown();
    }

    public void second(Runnable printSecond) throws InterruptedException {
        second.await();

        // printSecond.run() outputs "second". Do not change or remove this line.
        printSecond.run();
        third.countDown();
    }

    public void third(Runnable printThird) throws InterruptedException {
        third.await();
        
        // printThird.run() outputs "third". Do not change or remove this line.
        printThird.run();
    }
}
image.png

相关文章

网友评论

      本文标题:1114. 按序打印

      本文链接:https://www.haomeiwen.com/subject/edxlyhtx.html