fork download
  1. import java.util.concurrent.CountDownLatch;
  2.  
  3. class b {
  4. static final CountDownLatch countdown = new CountDownLatch(3);
  5.  
  6. public static void main(String[] args) {
  7.  
  8. for (int i = 0; i < 3; ++i) {
  9. Thread t = new Thread() {
  10. public void run() {
  11. System.out.printf("Starting on %d other threads.\n",
  12. countdown.getCount());
  13. countdown.countDown();
  14. System.out.printf("new on %d other threads.\n",
  15. countdown.getCount());
  16. try {
  17. countdown.await(); // waits until everyone reaches this
  18. // point
  19. // System.out.println("Go again : "
  20. // +countdown.getCount());
  21. } catch (Exception e) {
  22. }
  23. }
  24. };
  25. t.start();
  26.  
  27. }
  28. System.out.println("Go");
  29. }
  30.  
  31. }
Success #stdin #stdout 0.04s 247808KB
stdin
Standard input is empty
stdout
Starting on 3 other threads.
new on 2 other threads.
Starting on 2 other threads.
new on 1 other threads.
Go
Starting on 1 other threads.
new on 0 other threads.