JAVA多线程之中断机制(stop()、interrupted()、isInterrupted())
来源:互联网 发布:淘宝店铺主页 编辑:程序博客网 时间:2024/06/06 03:32
stop 方法
不安全,比如A线程被调用stop方法,被关闭后可能影响到其他线程。例如:
threadA线程拥有了监视器,这些监视器负责保护某些临界资源,比如说银行的转账的金额。当正在转账过程中,main线程调用 threadA.stop()方法。结果导致监视器被释放,其保护的资源(转账金额)很可能出现不一致性。比如,A账户减少了100,而B账户却没有增加100
interrupted 方法
public static boolean interrupted() { return currentThread().isInterrupted(true); }
静态方法,中断对象为调用线程,会清除中断状态
interrupt()方法有两个作用:
1. 一个是将线程的中断状态置位(中断状态由false变成true)
2. 另一个则是:让被中断的线程抛出InterruptedException异常
isInterrupted 方法
public boolean isInterrupted() { return isInterrupted(false); }
非静态方法,不会清除中断状态
0 0
- JAVA多线程之中断机制(stop()、interrupted()、isInterrupted())
- JAVA多线程之中断机制(stop()、interrupted()、isInterrupted())
- java多线程(五)中断 interrupt、interrupted 、isInterrupted
- JAVA多线程之interrupt、interrupted、isInterrupted
- 分析Java线程中断机制stop和interrupted的用法
- Java多线程中的interrupt、interrupted、isInterrupted
- Java多线程中interrupt interrupted isInterrupted
- 线程中断,interrupt(),interrupted,isInterrupted()
- Java中的线程中断:interrupt()、interrupted()和isInterrupted
- Java Thread的中断以及interrupt()、isInterrupted()、interrupted
- Java:interrupt()、interrupted()、isInterrupted()
- java isInterrupted()和interrupted()
- Java--interrupt(),interrupted(),isInterrupted()
- JAVA多线程编程之判断终止状态Interrupted和isInterrupted的区别
- 【多线程】interrupt、interrupted、isInterrupted方法
- java中interrupted()和isInterrupted
- 中断线程中 interrupt() isInterrupted interrupted
- 多线程中的Interrupt、Interrupted、IsInterrupted 的区分
- Leetcode 6. ZigZag Conversion The Solution of Python
- Leetcode 3(Java)
- 查找的方式
- errno值为0时的取值
- 2017 C4天梯 L2-020. 功夫传人
- JAVA多线程之中断机制(stop()、interrupted()、isInterrupted())
- 算法训练 字符串逆序
- SHA1摘要算法
- paho.mqtt.javascript 断开问题
- 蓝桥杯 矩阵翻硬币
- 大数阶乘
- 数据结构 —— 线性表
- Linux小记(三)
- Leetcode 7. Median of Two Sorted Arrays The Solution of Python