Skip to content

Instantly share code, notes, and snippets.

@martint
Created July 28, 2010 19:41
Show Gist options
  • Save martint/495976 to your computer and use it in GitHub Desktop.
Save martint/495976 to your computer and use it in GitHub Desktop.
public class X
{
public static void main(String[] args)
throws InterruptedException
{
final Thread t = new Thread(new Runnable() {
@Override
public void run()
{
synchronized (this) {
try {
wait();
}
catch (InterruptedException e) {
System.err.println("interrupted");
Thread.currentThread().interrupt();
}
}
}
});
t.start();
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable()
{
@Override
public void run()
{
System.err.println("interrupting");
t.interrupt();
System.err.println("waiting");
try {
t.join();
}
catch (InterruptedException e) {
System.err.println("shutdown interrupted");
}
}
}));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment