CountDownLatch Java
\nclass Foo {\n\n    private CountDownLatch latch1 = new CountDownLatch(1);\n    private CountDownLatch latch2 = new CountDownLatch(1);\n  \n    public Foo() {\
```\nclass Foo {\n\n    private CountDownLatch latch1 = new CountDownLatch(1);\n    private CountDownLatch latch2 = new CountDownLatch(1);\n  \n    public Foo() {\n        \n    }\n\n    public void first(Runnable printFirst) throws InterruptedException {\n        \n        // printFirst.run() outputs "first". Do not change or remove this line.\n        printFirst.run();\n        latch1.countDown();\n    }\n\n    public void second(Runnable printSecond) throws InterruptedException {\n        \n        latch1.await();\n        // printSecond.run() outputs "second". Do not change or remove this line.\n        printSecond.run();\n        latch2.countDown();\n       \n    }\n\n    public void third(Runnable printThird) throws InterruptedException {\n        // printThird.run() outputs "third". Do not change or remove this line.\n        latch2.await();\n        printThird.run();\n    }\n}\n```
[]