Summarize interrupt in Java based on jdk8

1. Interrupt knowledge points

The following summary is based on jdk8

This article will not fully explain interrupt, but only list some important points. Fully understand thread Interrupt can be found in resources.

Here are some new articles to help you understand resources:

翻译错误 TIMEOUT

After the interrupt method is called, for waiting / timed_ Threads in waiting status will throw interruptedexception * * up and set the interrupt flag bit false * *. For example, a thread calls thread sleep,Object. After wait().

If the thread has not been started (New) or terminated, calling interrupt () has no effect on it, and the interrupt flag bit is not set.

Best practice: sometimes some methods are not allowed to be interrupted or cancelled in design, but when other threads send interrupt requests, they also need to keep the marks to facilitate other callers to "understand the situation"

Some cancel operations can be realized by using interrupts. For example:

summary

The above is the summary of interrupt in Java based on jdk8 introduced by Xiaobian. I hope it will help you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>