linux起100个线程会宕机吗,这样终止线程,竟然会导致服务宕机?

/**

* Forces the thread to stop executing.

*

* If there is a security manager installed, its checkAccess

* method is called with this

* as its argument. This may result in a

* SecurityException being raised (in the current thread).

*

* If this thread is different from the current thread (that is, the current

* thread is trying to stop a thread other than itself), the

* security manager's checkPermission method (with a

* RuntimePermission("stopThread") argument) is called in

* addition.

* Again, this may result in throwing a

* SecurityException (in the current thread).

*

* The thread represented by this thread is forced to stop whatever

* it is doing abnormally and to throw a newly created

* ThreadDeath object as an exception.

*

* It is permitted to stop a thread that has not yet been started.

* If the thread is eventually started, it immediately terminates.

*

* An application should not normally try to catch

* ThreadDeath unless it must do some extraordinary

* cleanup operation (note that the throwing of

* ThreadDeath causes finally clauses of

* try statements to be executed before the thread

* officially dies). If a catch clause catches a

* ThreadDeath object, it is important to rethrow the

* object so that the thread actually dies.

*

* The top-level error handler that reacts to otherwise uncaught

* exceptions does not print out a message or otherwise notify the

* application if the uncaught exception is an instance of

* ThreadDeath.

*

* @exception SecurityException if the current thread cannot

* modify this thread.

* @see #interrupt()

* @see #checkAccess()

* @see #run()

* @see #start()

* @see ThreadDeath

* @see ThreadGroup#uncaughtException(Thread,Throwable)

* @see SecurityManager#checkAccess(Thread)

* @see SecurityManager#checkPermission

* @deprecated This method is inherently unsafe. Stopping a thread with

* Thread.stop causes it to unlock all of the monitors that it

* has locked (as a natural consequence of the unchecked

* ThreadDeath exception propagating up the stack). If

* any of the objects previously protected by these monitors were in

* an inconsistent state, the damaged objects become visible to

* other threads, potentially resulting in arbitrary behavior. Many

* uses of stop should be replaced by code that simply

* modifies some variable to indicate that the target thread should

* stop running. The target thread should check this variable

* regularly, and return from its run method in an orderly fashion

* if the variable indicates that it is to stop running. If the

* target thread waits for long periods (on a condition variable,

* for example), the interrupt method should be used to

* interrupt the wait.

* For more information, see

* Why

* are Thread.stop, Thread.suspend and Thread.resume Deprecated?.

*/

@Deprecated

public final void stop() {

SecurityManager security = System.getSecurityManager();

if (security != null) {

checkAccess();

if (this != Thread.currentThread()) {

security.checkPermission(SecurityConstants.STOP_THREAD_PERMISSION);

}

}

// A zero status value corresponds to "NEW", it can't change to

// not-NEW because we hold the lock.

if (threadStatus != 0) {

resume(); // Wake up thread if it was suspended; no-op otherwise

}

// The VM can handle all thread states

stop0(new ThreadDeath());

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值