gpt4 book ai didi

Java Thread.sleep

转载 作者:行者123 更新时间:2023-12-02 07:31:37 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com