Dark Horse programmer-thread interruption interruptedexception

Source: Internet
Author: User

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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.