@@ -0,0 +1,1908 @@
+package leetcode.concurrency;%0A%0Apublic class PrintInOrder %7B%0A%0A    private volatile String nextCall = %22first%22;%0A%0A    public void first(Runnable printFirst) throws InterruptedException %7B%0A        while (true) %7B%0A            if (nextCall.equals(%22first%22)) %7B%0A                printFirst.run();%0A                nextCall = %22second%22;%0A                break;%0A            %7D%0A        %7D%0A    %7D%0A%0A    public void second(Runnable printSecond) throws InterruptedException %7B%0A        while (true) %7B%0A            if (nextCall.equals(%22second%22)) %7B%0A                printSecond.run();%0A                nextCall = %22third%22;%0A                break;%0A            %7D%0A        %7D%0A    %7D%0A%0A    public void third(Runnable printThird) throws InterruptedException %7B%0A        while (true) %7B%0A            if (nextCall.equals(%22third%22)) %7B%0A                printThird.run();%0A                nextCall = %22first%22;%0A                break;%0A            %7D%0A        %7D%0A    %7D%0A%0A    public static void main(String%5B%5D args) throws InterruptedException %7B%0A        PrintInOrder printInOrder = new PrintInOrder();%0A        Thread first = new Thread(() -%3E %7B%0A            try %7B%0A                printInOrder.first(() -%3E System.out.println(%22first%22));%0A            %7D catch (InterruptedException e) %7B%0A                e.printStackTrace();%0A            %7D%0A        %7D);%0A        Thread second = new Thread(() -%3E %7B%0A            try %7B%0A                printInOrder.second(() -%3E System.out.println(%22second%22));%0A            %7D catch (InterruptedException e) %7B%0A                e.printStackTrace();%0A            %7D%0A        %7D);%0A        Thread third = new Thread(() -%3E %7B%0A            try %7B%0A                printInOrder.third(() -%3E System.out.println(%22third%22));%0A            %7D catch (InterruptedException e) %7B%0A                e.printStackTrace();%0A            %7D%0A        %7D);%0A%0A        third.start();%0A        first.start();%0A        second.start();%0A%0A        first.join();%0A        second.join();%0A        third.join();%0A    %7D%0A%7D%0A

Add PrintInOrde