Java Phaser
Code\n\nclass Foo {\n    private Phaser phaser = new Phaser(3);\n\n    public Foo() { }\n\n    public void first(Runnable printFirst) throws InterruptedExceptio
# Code\n```\nclass Foo {\n    private Phaser phaser = new Phaser(3);\n\n    public Foo() { }\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        phaser.arriveAndDeregister();\n    }\n\n    public void second(Runnable printSecond) throws InterruptedException {\n        while (phaser.getPhase() != 1) {\n          phaser.arriveAndAwaitAdvance();\n        }\n        // printSecond.run() outputs "second". Do not change or remove this line.\n        printSecond.run();\n        phaser.arriveAndDeregister();\n    }\n\n    public void third(Runnable printThird) throws InterruptedException {\n        while (phaser.getPhase() != 2) {\n          phaser.arriveAndAwaitAdvance();\n        }\n        // printThird.run() outputs "third". Do not change or remove this line.\n        printThird.run();\n    }\n}\n```
['Java']