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

标签 java multithreading

官方 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/

相关文章:

java - 异常的 Android UI 问题 : android:scaleType="fitXY and match_parent will not increase the size of an ImageView -

java - 错误 : No URL for ServletContext resource when running Spring integrated test

java - 为什么要 "Make autowired dependencies explicit"?

java - Java J2ME 中消息传递到异步工作线程

java - 如何在 Java 中分析分布式应用程序?

java - 如何消除 Java 安全警告

java - 在 JMeter 中为不同的线程使用不同的变量

c++ - 我应该使用线程编程来混合 2 个音频流吗?

Python 线程返回值

android - 线程只循环一次