fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. final Ideone one = new Ideone();
  13. Thread t = new Thread (new Runnable(){
  14. public void run(){
  15. int i = 0;
  16. while(i < 100) {
  17. try {
  18. one.methodB();
  19. } catch(Throwable e){System.out.println(e);}
  20. System.out.println("methodB called!");
  21. i++;
  22. }
  23.  
  24. }
  25. });
  26. t.start();
  27.  
  28. try{
  29. one.sync = new Object();
  30. t.join();
  31. }catch(Throwable e){System.out.println(e);}
  32. finally{
  33. System.out.println("Done");
  34. }
  35. }
  36. private Object sync = new Object();
  37. public void methodA() throws InterruptedException {
  38. synchronized(this.sync){
  39. Thread.sleep(1000);
  40. }
  41. }
  42. public void methodB() throws InterruptedException {
  43. synchronized(this.sync){
  44. methodA();
  45. }
  46. }
  47. }
Time limit exceeded #stdin #stdout 5s 380544KB
stdin
Standard input is empty
stdout
methodB called!
methodB called!
methodB called!
methodB called!
methodB called!
methodB called!
methodB called!
methodB called!
methodB called!
methodB called!