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. method1();
  13. }
  14. static boolean method2Continue = false;
  15.  
  16. public static void method1() {
  17. Thread thread = new Thread(() -> method2());
  18. thread.start();
  19. if(true){
  20. for(int i = 0; i < 10000000; i++); // delay to allow method2 to start
  21. System.out.println("Allowing method2 to continue");
  22. method2Continue = true;
  23. }
  24. thread.interrupt();
  25. }
  26. public static void method2() {
  27. // ...
  28. System.out.println("method2");
  29. while(!method2Continue);
  30. System.out.println("method2 has been allowed to continue");
  31. // ...
  32. }
  33. }
Success #stdin #stdout 0.23s 320960KB
stdin
Standard input is empty
stdout
method2
Allowing method2 to continue
method2 has been allowed to continue