Skip to content

Instantly share code, notes, and snippets.

@LBRapid
Last active August 29, 2015 14:05
Show Gist options
  • Save LBRapid/0d7b9d36d65287316433 to your computer and use it in GitHub Desktop.
Save LBRapid/0d7b9d36d65287316433 to your computer and use it in GitHub Desktop.
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