fork download
  1. class PingPong2 {
  2. synchronized void hit(long n) {
  3. for(int i = 1; i < 3; i++)
  4. System.out.print(n + "-" + i + " ");
  5. }
  6. }
  7.  
  8. class Tester implements Runnable {
  9. static PingPong2 pp2 = new PingPong2();
  10. public static void main(String[] args) {
  11. new Thread(new Tester()).start();
  12. new Thread(new Tester()).start();
  13. }
  14. public void run() { pp2.hit(Thread.currentThread().getId()); }
  15. }
Success #stdin #stdout 0.15s 44476KB
stdin
Standard input is empty
stdout
10-1 10-2 11-1 11-2