每当我们在代码中尝试 Threads.sleep 时,我们都必须捕获 InterruptedException。这意味着线程无法在我们指定的时间内 hibernate ,对吧?那么如何才能中断我们置于 sleep 状态的线程呢?谁能解释一下这个概念?
最佳答案
如何中断线程?我可以调用Thread.interrupt()就在上面。
来自here :
An interrupt is an indication to a thread that it should stop what it is doing and do something else. It's up to the programmer to decide exactly how a thread responds to an interrupt, but it is very common for the thread to terminate. This is the usage emphasized in this lesson.
值得一读this article from JavaSpecialists了解如何干净地处理中断。
关于Java Thread.sleep,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12838502/