当前位置: 技术问答>java相关
为什么、我继承了THREAD类后对应超类的STOP方法被加了删除线,不能用?
来源: 互联网 发布时间:2015-11-17
本文导语: 我用JBUILDER7,自己写个类派生THREAD,可是我用直接在自己类里用超类的STOP方法 提示时候STOP加了删除线,这是什么意思 编译时候还会有以下的警告 "XChatServer.java": Warning #: 368 : method stop() in class java.lang.Thread has...
我用JBUILDER7,自己写个类派生THREAD,可是我用直接在自己类里用超类的STOP方法
提示时候STOP加了删除线,这是什么意思
编译时候还会有以下的警告
"XChatServer.java": Warning #: 368 : method stop() in class java.lang.Thread has been deprecated at line 186, column 21
希望高手指点
提示时候STOP加了删除线,这是什么意思
编译时候还会有以下的警告
"XChatServer.java": Warning #: 368 : method stop() in class java.lang.Thread has been deprecated at line 186, column 21
希望高手指点
|
Why is Thread.stop deprecated?
Because it is inherently unsafe. Stopping a thread causes it to unlock all the monitors that it has locked. (The monitors are unlocked as the ThreadDeath exception propagates up the stack.) If any of the objects previously protected by these monitors were in an inconsistent state, other threads may now view these objects in an inconsistent state. Such objects are said to be damaged. When threads operate on damaged objects, arbitrary behavior can result. This behavior may be subtle and difficult to detect, or it may be pronounced. Unlike other unchecked exceptions, ThreadDeath kills threads silently; thus, the user has no warning that his program may be corrupted. The corruption can manifest itself at any time after the actual damage occurs, even hours or days in the future.
Because it is inherently unsafe. Stopping a thread causes it to unlock all the monitors that it has locked. (The monitors are unlocked as the ThreadDeath exception propagates up the stack.) If any of the objects previously protected by these monitors were in an inconsistent state, other threads may now view these objects in an inconsistent state. Such objects are said to be damaged. When threads operate on damaged objects, arbitrary behavior can result. This behavior may be subtle and difficult to detect, or it may be pronounced. Unlike other unchecked exceptions, ThreadDeath kills threads silently; thus, the user has no warning that his program may be corrupted. The corruption can manifest itself at any time after the actual damage occurs, even hours or days in the future.
|
能不能说具体点,或者把程序贴出来看看。