Basically, the commits in this repo:
- Write your code that you wish you had: f9372d7
- inspired by T/BDD, which I am very much used to.
- Use Java's CyclicBarrier to make it happen: 9a82c3f
- So we can learn the interface
- Replace CyclicBarrier with a stub implementation: 15971e2
- also simplify the API's cruft - we don't need those exceptions to be caught for the purpose of this demo
git clone <this repo> && cd <repo>javac *.java && java BarrierExample- Output:
Thread-1: running
Thread-1: this should happen before reaching the barrier
Thread-2: running
Thread-2: this should happen before reaching the barrier
Thread-3: running
Thread-3: this should happen before reaching the barrier
Thread-4: running
Thread-4: this should happen before reaching the barrier
Thread-5: running
Thread-5: this should happen before reaching the barrier
Thread-6: running
Thread-6: this should happen before reaching the barrier
Thread-7: running
Thread-7: this should happen before reaching the barrier
Thread-8: running
Thread-8: this should happen before reaching the barrier
Thread-9: running
Thread-9: this should happen before reaching the barrier
Thread-10: running
Thread-10: this should happen before reaching the barrier
Thread-10: this should happen after the barrier
Thread-7: this should happen after the barrier
Thread-8: this should happen after the barrier
Thread-5: this should happen after the barrier
Thread-2: this should happen after the barrier
Thread-6: this should happen after the barrier
Thread-9: this should happen after the barrier
Thread-1: this should happen after the barrier
Thread-4: this should happen after the barrier
Thread-3: this should happen after the barrier
Hence, it works for this simplistic demo purpose.