Java using Semaphores
\nimport java.util.concurrent.Semaphore;\nclass Foo {\n\n    private final Semaphore second;\n    private final Semaphore third;\n    \n    public Foo() {      
```\nimport java.util.concurrent.Semaphore;\nclass Foo {\n\n    private final Semaphore second;\n    private final Semaphore third;\n    \n    public Foo() {        \n        second = new Semaphore(0);\n        third = new Semaphore(0);\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        second.release();\n    }\n\n    public void second(Runnable printSecond) throws InterruptedException {\n        second.acquire();\n        // printSecond.run() outputs "second". Do not change or remove this line.\n        printSecond.run();\n        third.release();\n    }\n\n    public void third(Runnable printThird) throws InterruptedException {\n        third.acquire();\n        // printThird.run() outputs "third". Do not change or remove this line.\n        printThird.run();        \n    }\n}\n```
[]