Last active
August 29, 2015 14:05
-
-
Save LBRapid/0d7b9d36d65287316433 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Uninterruptible { | |
public static void main(String[] args) throws InterruptedException { | |
final Object o1 = new Object(); final Object o2 = new Object(); | |
Thread t1 = new Thread() { | |
public void run() { | |
try { | |
synchronized(o1) { | |
Thread.sleep(1000); | |
synchronized(o2) {} | |
} | |
} catch (InterruptedException e) { System.out.println("t1 interrupted"); } | |
} | |
}; | |
Thread t2 = new Thread() { | |
public void run() { | |
try { | |
synchronized(o2) { | |
Thread.sleep(1000); | |
synchronized(o1) {} | |
} | |
} catch (InterruptedException e) { System.out.println("t2 interrupted"); } | |
} | |
}; | |
t1.start(); t2.start(); | |
Thread.sleep(2000); | |
t1.interrupt(); t2.interrupt(); | |
t1.join(); t2.join(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment