gpt4 book ai didi

java - 为什么 Thread.stop 在 Thread.interrupt 不起作用的情况下不起作用?

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:56:57 26 4
gpt4 key购买 nike

官方 Sun Oracle 对 Thread.stop() 的立场是不应使用它。在其他参数中,they write :

It should be noted that in all situations where a waiting thread doesn't respond to Thread.interrupt, it wouldn't respond to Thread.stop either.

但是我不明白。如果一个线程正忙于积极处理某事(不仅仅是等待或阻塞外部资源)并且没有明确检查中断标志,Thread.interrupt() 不会在 时什么都不做吗>Thread.stop() 仍然有效(throw ThreadDeath)?

最佳答案

But I do not understand that. If a thread is busy actively working on something (not just waiting or blocking on an external resource) and doesn't explicitly check the interrupt flag, wouldn't Thread.interrupt() do nothing while Thread.stop() will still work (throw ThreadDeath)?

我认为您误解了引用的文字。它指的是正在等待的线程,而不是正在运行的线程。具体是指如下情况:

  • 当线程在 I/O 调用中被阻塞时,低级 JVM 实现问题会阻止它响应 stopinterrupt

  • 不想被停止的线程可以捕获 ThreadDeath,这类似于不想被中断的线程只是忽略标志。

关于java - 为什么 Thread.stop 在 Thread.interrupt 不起作用的情况下不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5244312/

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