为什么在Thread.interrupt不起作用的情况下Thread.stop不起作用? [英] Why doesn't Thread.stop work in situations where Thread.interrupt doesn't work?

查看:108
本文介绍了为什么在Thread.interrupt不起作用的情况下Thread.stop不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Thread.stop()上正式的 Sun Oracle立场是不应使用它.除其他参数外,他们写:

The official Sun Oracle stance on Thread.stop() is that it should not be used. Among other arguments, they write:

应该注意,在所有等待线程不响应Thread.interrupt的情况下,它也不响应Thread.stop.

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()仍然可以工作(抛出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)?

推荐答案

但是我不明白.如果一个线程正忙于主动地处理某些事情(而不仅仅是在外部资源上等待或阻塞),并且没有显式检查中断标志,那么当Thread.stop()仍然可以工作时,Thread.interrupt()不会做任何事情(抛出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 think you misunderstand the quoted text. It refers to a thread that is waiting, not a thread that is running. Specifically, it is referring to cases like the following:

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

不希望被停止的线程可以捕获ThreadDeath,这类似于不希望仅仅忽略该标志就不想被中断的线程.

A thread that doesn't want to be stopped can catch ThreadDeath, and this is analogous to a thread that doesn't want to be interrupted simply ignoring the flag.

这篇关于为什么在Thread.interrupt不起作用的情况下Thread.stop不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆