Java | CountDownLatch simple solution
\nimport java.util.concurrent.CountDownLatch;\n\nclass Foo {\n\n    private final CountDownLatch firstLatch = new CountDownLatch(1);\n    private final CountDow
```\nimport java.util.concurrent.CountDownLatch;\n\nclass Foo {\n\n    private final CountDownLatch firstLatch = new CountDownLatch(1);\n    private final CountDownLatch secondLatch = new CountDownLatch(1);\n\n    public Foo() {\n\n    }\n\n    public void first(Runnable printFirst) throws InterruptedException {\n        // printFirst.run() outputs "first". Do not change or remove this line.\n        printFirst.run();\n        \n        firstLatch.countDown();\n    }\n\n    public void second(Runnable printSecond) throws InterruptedException {\n        firstLatch.await();\n        // printSecond.run() outputs "second". Do not change or remove this line.\n        printSecond.run();\n        \n        secondLatch.countDown();\n    }\n\n    public void third(Runnable printThird) throws InterruptedException {\n        secondLatch.await();\n        // printThird.run() outputs "third". Do not change or remove this line.\n        printThird.run();\n    }\n}\n```
['Java']