educative.io

Educative

Thread.interrupted() is not clearing the interrupted flag

See the following output provided by the given code snippet:

About to wake up the sleepy thread ...
Woke up sleepy thread ...
I am too sleepy... Let me sleep for an hour.
The interrupt flag is cleard : false false
Oh someone woke me up ! 
The interrupt flag is set now : true true

The lines written below the code: On line 22 we deliberately call the object method first followed by the static method. If we reverse the ordering of the two method calls on line 22, the output for the line would be true and false , instead of true and true .

As written in the text, the output should be true and false, but the output provided when the code is run is true and true. It means that interrupted flag is not cleared by the static method.