interrupt()的问题?

xlpang_hn 2005-04-09 07:35:44
请问,interrupt()和已废掉的stop()有什么不同?
感觉interrupt()也是将线程结束,为什么不将它也废掉呢?
...全文
78 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
xlpang_hn 2005-04-10
  • 打赏
  • 举报
回复
谢了
star_str 2005-04-10
  • 打赏
  • 举报
回复
interrupt在我影响中是不结束线程对对象级别的占有,而stop就相当于强迫让线程结束,让出级别占有

If this thread is blocked in a Selector then the thread's interrupt status will be set and it will return immediately from the selection operation, possibly with a non-zero value, just as if the selector's wakeup method were invoked.

调用interrupt会使run立刻返回,结束interrupt后相当于调用了wakeup方法
晨星 2005-04-10
  • 打赏
  • 举报
回复
嗯,我据的是。wait的地方会被抛出一个Exception。
xlpang_hn 2005-04-09
  • 打赏
  • 举报
回复
那就是说调用该方法后,并不影响线程的运行情况,只是设置一下status吗?
lovelife_821106 2005-04-09
  • 打赏
  • 举报
回复
这论坛怎么找不到提问的地方呀?各位帮帮忙呀!谢谢啦
! 13913300216
晨星 2005-04-09
  • 打赏
  • 举报
回复
public void interrupt()
Interrupts this thread.
First the checkAccess method of this thread is invoked, which may cause a SecurityException to be thrown.

If this thread is blocked in an invocation of the wait(), wait(long), or wait(long, int) methods of the Object class, or of the join(), join(long), join(long, int), sleep(long), or sleep(long, int), methods of this class, then its interrupt status will be cleared and it will receive an InterruptedException.

If this thread is blocked in an I/O operation upon an interruptible channel then the channel will be closed, the thread's interrupt status will be set, and the thread will receive a ClosedByInterruptException.

If this thread is blocked in a Selector then the thread's interrupt status will be set and it will return immediately from the selection operation, possibly with a non-zero value, just as if the selector's wakeup method were invoked.

If none of the previous conditions hold then this thread's interrupt status will be set.
晨星 2005-04-09
  • 打赏
  • 举报
回复
interrupt不是结束线程,是改变线程的状态。
比如原来一个线程在wait,那么interrupt可以告诉他:“好了,该干啥干啥去吧,别整天吃饱了没事干就在那里wait啦。。。”

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧