Created
April 16, 2015 17:34
-
-
Save danielshaya/a272bcfea275b0038aa0 to your computer and use it in GitHub Desktop.
Interrupt example
This file contains 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
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