I'm new to Java and is trying to the concept of "interrupt status flag" as part of Java concurrency. I have read Oracle's official documents and tutorials on the topic and is still unclear as to what exactly is a "interrupt status flag" and how it works. Could someone please kindly provide me with some explanation?
Asked
Active
Viewed 384 times
1
-
2It's a boolean state variable in the `Thread` class, set by `Thread.interrupt()` and cleared by `Thread.interrupted().` Nothing much to understand there, and it's well documented in both the Javadoc and the Java Tutorial. Either too trivial or too broad. – user207421 Feb 16 '16 at 05:37
-
see [How can I kill a thread? without using stop();](http://stackoverflow.com/q/5915156/217324) – Nathan Hughes Feb 18 '16 at 14:17
1 Answers
2
It is a marker that indicates to stop thread.
public static void main(String[] args) throws InterruptedException {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
while(!Thread.currentThread().interrupted()) {
System.out.println("Thread is not interrupted");
}
System.out.println("Thread is interrupted");
}
});
thread.start();
Thread.sleep(2000);
thread.interrupt();
}

FruitDealer
- 164
- 1
- 11
-
1@dzjustinli If this answer satisfies you it is difficult to see what you didn't understand in the Javadoc or the Oracle Tutorial. – user207421 Feb 16 '16 at 06:44