fork download
  1. class SynchTest {
  2. public static void main(String[] args) {
  3. new Thread(new Task()).start();
  4. new Thread(new Task()).start();
  5. new Thread(new Task()).start();
  6. }
  7.  
  8. static class Task implements Runnable {
  9. long start;
  10.  
  11. Task() {
  12. this.start = System.currentTimeMillis();
  13. }
  14.  
  15. static final Object STATIC_MONITOR = new Object();
  16.  
  17. @Override
  18. public void run() {
  19. synchronized (STATIC_MONITOR) {
  20. try {
  21. Thread.sleep(1000);
  22. } catch (InterruptedException ignored) {
  23. }
  24. System.out.println(System.currentTimeMillis() - start);
  25. }
  26. }
  27. }
  28. }
Success #stdin #stdout 0.05s 2380800KB
stdin
Standard input is empty
stdout
1000
2001
3001