惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
博客园 - 聂微东
Application and Cybersecurity Blog
Application and Cybersecurity Blog
MyScale Blog
MyScale Blog
罗磊的独立博客
H
Help Net Security
L
LangChain Blog
T
Threat Research - Cisco Blogs
量子位
S
Securelist
Last Week in AI
Last Week in AI
L
Lohrmann on Cybersecurity
T
The Exploit Database - CXSecurity.com
P
Privacy International News Feed
The Hacker News
The Hacker News
Vercel News
Vercel News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Blog of Author Tim Ferriss
T
Threatpost
Security Latest
Security Latest
P
Palo Alto Networks Blog
Microsoft Security Blog
Microsoft Security Blog
NISL@THU
NISL@THU
F
Full Disclosure
WordPress大学
WordPress大学
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Stack Overflow Blog
Stack Overflow Blog
C
Check Point Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Heimdal Security Blog
J
Java Code Geeks
Recorded Future
Recorded Future
Hugging Face - Blog
Hugging Face - Blog
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
阮一峰的网络日志
阮一峰的网络日志
U
Unit 42
B
Blog RSS Feed
月光博客
月光博客
C
Cisco Blogs
V
Visual Studio Blog
D
DataBreaches.Net
H
Hacker News: Front Page
博客园 - 叶小钗
N
News and Events Feed by Topic
爱范儿
爱范儿
A
Arctic Wolf

博客园 - 那只狐狸

线程与GC 神奇的Task.WaitALl Redis的淘汰策略 压测工具k6 C#的Lock可以锁什么? SqlServer高性能批量插入 二叉树 二叉搜索树 AVL树 红黑树 关于GC 线上bug线下很难重现时的一次处理 自动化测试和联调的工具---apifox 事务管理思考 sleep、yield、wait的区别 线程异常 线程 volatile synchronized在线程安全上的区别 jms amqp activemq rabbitmq的区别 servlet不是线程安全的 雪花算法 mysql在海量数据时的处理方案
JAVA线程中断
那只狐狸 · 2019-12-15 · via 博客园 - 那只狐狸

建议自定义标志位和IsInterrupted标志位结合使用

使用自定义标志位的方法如果是阻塞方法(sleep),则自定义标志位无效;

如果单单使用IsInterrupted标志位,又因为java的多线程是协作方式而不是强制方式,所以可能不理会“打招呼”式的中断请求(特别是IO通信方法);

只有两个标志位都为真时才执行业务逻辑

1.不安全的取消:stop、suspend、resume;强制性、暴力的,不释放资源,可能死锁等

2. 处理不可中断的阻塞,比如io的读写、nio的selector的select,可以关闭底层的套接字;

3.死锁状态是不响应中断的

4.如何既可以响应普通的中断又可以处理不可中断的阻塞呢?

覆盖线程的interrupt方法

5.线程阻塞式API(sleep wait)被中断后,标志位会改成false,并抛出异常;所以捕获到中断异常后 需要设置标志位(特别是线程中有循环调用)