fork download
  1. class Main {
  2.  
  3. public static volatile Callee callee;
  4.  
  5. static class Callee {
  6. public void call() { System.out.println("Method called"); }
  7.  
  8. public Callee() {
  9. Main.callee = this;
  10. try {Thread.sleep(1000);} catch (Exception e) {}
  11. System.out.println("I am constructed!");
  12. }
  13. }
  14.  
  15. static class Creator implements Runnable {
  16. public void run() { Main.callee = new Callee(); }
  17. }
  18.  
  19. static class Caller implements Runnable {
  20. public void run() {
  21. while (Main.callee == null);
  22. Main.callee.call();
  23. }
  24. }
  25.  
  26. public static void main(String... args) {
  27. new Thread(new Creator()).start();
  28. new Thread(new Caller()).start();
  29. }
  30. }
Success #stdin #stdout 0.03s 246272KB
stdin
Standard input is empty
stdout
Method called
I am constructed!