Skip to content

Instantly share code, notes, and snippets.

@danielshaya
Created April 16, 2015 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielshaya/a272bcfea275b0038aa0 to your computer and use it in GitHub Desktop.
Save danielshaya/a272bcfea275b0038aa0 to your computer and use it in GitHub Desktop.
Interrupt example
package util;
/**
* Created by daniel on 16/04/15.
*/
public class Interrupt {
public static void main(String[] args) {
Thread sleeperThread = new Thread(){
public void run(){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
System.out.println(isInterrupted()); //prints false
interrupt();
System.out.println(isInterrupted()); //prints true
System.out.println(interrupted()); //prints true
System.out.println(isInterrupted()); //prints false
}
}
};
sleeperThread.start();
sleeperThread.interrupt();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment