Java Solution - BlockingQueue-s
Using 2 separate blocking queues each of capacity of 1. \n\n\nimport java.util.concurrent.ArrayBlockingQueue;\nimport java.util.concurrent.BlockingQueue;\n\ncla
Using 2 separate blocking queues each of capacity of 1. \n\n```\nimport java.util.concurrent.ArrayBlockingQueue;\nimport java.util.concurrent.BlockingQueue;\n\nclass FooBar {\n    private int n;\n    final BlockingQueue<Boolean> queue1 = new ArrayBlockingQueue<>(1);\n    final BlockingQueue<Boolean> queue2 = new ArrayBlockingQueue<>(1);\n\n    public FooBar(int n) {\n        this.n = n;        \n    }\n\n    public void foo(Runnable printFoo) throws InterruptedException {\n        \n        for (int i = 0; i < n; i++) {\n            \n        \t// printFoo.run() outputs "foo". Do not change or remove this line.\n        \tprintFoo.run();\n            queue1.offer(Boolean.TRUE);\n            queue2.take();\n        }\n    }\n\n    public void bar(Runnable printBar) throws InterruptedException {\n        \n        for (int i = 0; i < n; i++) {\n            queue1.take();\n            // printBar.run() outputs "bar". Do not change or remove this line.\n        \tprintBar.run();\n            queue2.offer(Boolean.TRUE);\n            \n        }\n    }\n}\n```
['Java']