fork(1) 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. try{
  16. one.methodB();
  17. }catch(Throwable e){System.out.println(e);}
  18. System.out.println("Thread done");
  19. }
  20. });
  21. t.start();
  22. t.join();
  23. try{
  24. one.methodB();
  25. }catch(Throwable e){System.out.println(e);}
  26. finally{
  27. System.out.println("Done");
  28. }
  29. }
  30. private Object sync = new Object();
  31. public void methodA() throws InterruptedException {
  32. synchronized(this.sync){
  33. System.out.println("Throwing error");
  34. throw new InterruptedException();
  35. }
  36. }
  37. public void methodB() throws InterruptedException {
  38. synchronized(this.sync){
  39. methodA();
  40. }
  41. }
  42. }
Success #stdin #stdout 0.07s 380480KB
stdin
Standard input is empty
stdout
Throwing error
java.lang.InterruptedException
Thread done
Throwing error
java.lang.InterruptedException
Done