博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Thread的中断
阅读量:7232 次
发布时间:2019-06-29

本文共 840 字,大约阅读时间需要 2 分钟。

hot3.png

1,如果线程t通过Object的wait、或者线程的join 、sleep方法被阻塞, 那么当你(在当前线程中)对t发送t.interrupt 消息时, t的中断为被清除,同时t将收到 InterruptedException 异常。

2,如果t阻塞在的I/O操作中, 这时对t 发送中断消息会将t 的中断为置1, 并将收到 an 异常, 同时 io管道关闭。

3,如果线程t阻塞在 Selector 中, t收到中断消息后立马退出,不会收到异常。

public void interrupt ()

Added in 

Posts an interrupt request to this Thread. The behavior depends on the state of this Thread:

  • Threads blocked in one of Object's wait() methods or one of Thread's join() or sleep() methods will be woken up, their interrupt status will be cleared, and they receive an .

  • Threads blocked in an I/O operation of an  will have their interrupt status set and receive an. Also, the channel will be closed.

  • Threads blocked in a  will have their interrupt status set and return immediately. They don't receive an exception in this case.

    See Also

转载于:https://my.oschina.net/u/255456/blog/341203

你可能感兴趣的文章
Nodejs差不多也到顶峰了吧?
查看>>
Spring Boot 自动配置原理
查看>>
SpringCloud组件:你的Eureka服务注册中心安全吗?
查看>>
Laravel核心代码学习 -- 观察者模式
查看>>
关于面试题“ArrayList循环remove()要用Iterator”的研究
查看>>
EventHelper 异步并发处理
查看>>
炫酷的圆环加载及数字滚动效果(上)
查看>>
Promise异步函数顺序执行的四种方法
查看>>
vue 源码:如何调试源码
查看>>
Flutter beta3 使用感受
查看>>
如何使用WijmoJS 纯前端设计器,快速生成 Angular 应用
查看>>
理解ES6 proxy&reflection
查看>>
『中级篇』Docker 水平扩展和负载均衡(40)
查看>>
idea中file-template的使用
查看>>
JavaScript 浅谈 button 和 input type=button 的区别
查看>>
未知领域
查看>>
混合云存储组合拳:基于云存储网关与混合云备份的OSS数据备份方案
查看>>
MIT最新研究:隔着一堵墙,“看透"你的心!
查看>>
GraphQL搭配MongoDB入门项目实战
查看>>
APP实现再次查询功能
查看>>