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