[Java] Simple CountDownLatch solution
CountDownLatch seems a good fit for this, from java doc " A synchronization aid that allows one or more threads to wait until, a set of operations being perform
CountDownLatch seems a good fit for this, from java doc " A synchronization aid that allows one or more threads to wait until, a set of operations being performed in other threads completes. "\n\n```\nimport java.util.concurrent.CountDownLatch;\n\nclass Foo {\n    \n    private final CountDownLatch l2;\n    private final CountDownLatch l3;\n    \n    public Foo() {\n        l2 = new CountDownLatch(1);\n        l3 = new CountDownLatch(1);\n    }\n\n    public void first(Runnable printFirst) throws InterruptedException {\n        printFirst.run();\n        l2.countDown();\n    }\n\n    public void second(Runnable printSecond) throws InterruptedException {\n        l2.await();\n        printSecond.run();\n        l3.countDown();\n    }\n\n    public void third(Runnable printThird) throws InterruptedException {\n        l3.await();\n        printThird.run();\n    }\n}\n```\n\n
[]