fork(19) download
  1. import java.*;
  2.  
  3.  
  4. public class Main
  5. {
  6.  
  7. static Object A = new Object();
  8. static Object B = new Object();
  9.  
  10. static class AB implements Runnable {
  11. public void run() {
  12. synchronized (A) {
  13. Thread.sleep(100);
  14. synchronized (B) {
  15. Thread.sleep(100);
  16. doWork("first");
  17. }}}}
  18.  
  19. static class BA implements Runnable {
  20. public void run() {
  21. synchronized (B) {
  22. Thread.sleep(100);
  23. synchronized (A) {
  24. Thread.sleep(100);
  25. doWork("second");
  26. }}}}
  27.  
  28.  
  29. public static void doWork(String in)
  30. {
  31. System.out.println( "I'm doing work!" + in);
  32. }
  33.  
  34. public static void main(String[] args)
  35. {
  36.  
  37. AB a = new AB();
  38. BA b = new BA();
  39.  
  40. Thread t1 = new Thread(a);
  41. t1.start();
  42. Thread t2 = new Thread(b);
  43. t2.start();
  44.  
  45. }
  46.  
  47. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:13: unreported exception java.lang.InterruptedException; must be caught or declared to be thrown
			Thread.sleep(100);
			            ^
Main.java:15: unreported exception java.lang.InterruptedException; must be caught or declared to be thrown
				Thread.sleep(100);
				            ^
Main.java:22: unreported exception java.lang.InterruptedException; must be caught or declared to be thrown
			Thread.sleep(100);
			            ^
Main.java:24: unreported exception java.lang.InterruptedException; must be caught or declared to be thrown
				Thread.sleep(100);
				            ^
4 errors
stdout
Standard output is empty