sleep()只能让当前线程睡眠,当前线程是自愿的。
如果让sleep()成为实例方法,当前线程可以直接sleep别的线程,会引入很多多线程的问题。
Thread中很多方法被弃用,destroy(), suspend(), stop(),resume()这些实例方法;剩下的只有一些static方法和只对当前线程操作方法。 为什么destroy(), suspend(), stop(),resume()这些实例方法被弃用?
Why is Thread.stop deprecated? from(http://docs.oracle.com/javase/7/docs/technotes/guides/concurrency/threadPrimitiveDeprecation.html)
Because it is inherentlyunsafe. Stopping a thread causes it to unlock all the monitors that it has locked. (The monitors are unlocked as the ThreadDeath exception propagatesup 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.
[ˈprɒpəgeɪt
|
ˈ[ɑ:bɪtrəri]乱; 随意的,任性的,随心所欲的; 主观的,武断的; 霸道的,专制的,专横的,独断独行的;