Simple Java Solution using booleans for locking
class Foo {\n    \n        private volatile boolean executedFirst,executedSecond;\n        public Foo() {}\n    \n        public void first(Runnable printFirst)
class Foo {\n    \n        private volatile boolean executedFirst,executedSecond;\n        public Foo() {}\n    \n        public void first(Runnable printFirst) throws InterruptedException {\n            executedFirst = true;\n            printFirst.run();\n        }\n    \n        public void second(Runnable printSecond) throws InterruptedException {\n    \n            while (!executedFirst);\n            executedSecond = true;\n            printSecond.run();\n        }\n    \n        public void third(Runnable printThird) throws InterruptedException {\n            while (!executedSecond);\n            printThird.run();\n        }
[]