1

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?

halfer
  • 19,471
  • 17
  • 87
  • 173
Thor
  • 9,110
  • 14
  • 56
  • 125

1 Answers1

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
  • 174
  • 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