I recently learned multithreading and often used thread. sleep (long milltime) method also knows that it will throw an exception, but it is not very clear about what exceptions it throws (the disadvantage of Automatic Generation Using eclipse ), today, I specially studied the exception interruptedexception thrown by it, which is summarized as follows:
Interrupted indicates that the thread is interrupted. The exception is generated when the current thread is interrupted. So what is thread interruption? The concept is as follows: each thread maintains a bool variable, indicating that the thread is in the interrupted (true) or non-interrupted (false) state ). When the thread is initially interrupted, the variable is false. The bool value of this variable can be read through the thread. isinterrupted () method, and the interrupt is cleared through the thread. interrupted () method (that is, the interrupt variable is set to false ).
How can this interruption be handled correctly?
To be continued