Java Thread.sleep

标签 java multithreading

每当我们在代码中尝试 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/

相关文章:

java同步

windows - 将 Win32 API 功能与 pthreads 一起使用/从 pthreads 使用

java - 如何防止 Eclipse 导入嵌套类?

java - 有没有办法在 JavaFX LineChart 中断开串联的 2 个点?

java - Java String 真的是不可变的吗?

c# - Parallel.For 与 Parallel.Invoke

java - 如何控制 JTextArea 上显示的内容?

Java 多态性与 ArrayList

c++ - 如何用多态管理线程资源? (C++)

c++ - 处理与 tbb 顺序的大数据