InterruptionInJava
package com.test;
public class InterruptionInJava implements Runnable{
public static void main(String[] args) throws InterruptedException {
Thread testThread = new Thread(new InterruptionInJava(),"InterruptionInJava");
//start thread
testThread.start();
//interrupt thread
testThread.interrupt();
System.out.println("main end");
}
@Override
public void run() {
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
System.out.println(Thread.currentThread().isInterrupted());
Thread.currentThread().interrupt();
System.out.println(Thread.currentThread().isInterrupted());
}
while(true){
if(Thread.currentThread().isInterrupted()){
System.out.println("Yes,I am interruted,but I am still running");
}else{
System.out.println("not yet interrupted");
}
}
}
}
InterruptionInJava的更多相关文章
- Thread之八:interrupt中断
Java中断机制是一种协作机制,也就是说通过中断并不能直接终止另一个线程,它只是要求被中断线程在合适的时机中断自己,这需要被中断的线程自己处理中断.这好比是家里的父母叮嘱在外的子女要注意身体,但子女是 ...
- Java中的Interrupt使用
初心 用interrupt中断程序 初步实现 public class InterruptionInJava implements Runnable{ @Override public void ru ...
- Java并发分析—Lock
1.Lock 和 Condition 当使用synchronied进行同步时,可以在同步代码块中只用常用的wait和notify等方法,在使用显示锁的时候,将通过Condition对象与任意Lock实 ...
随机推荐
- Border Layout
------------------siwuxie095 根面板 contentPane 的默认布局就是 Border Layout B ...
- vue 生命周期小结
生命周期小结生命周期钩子的一些使用方法: beforecreate : 可以在这加个loading事件,在加载实例时触发 created : 初始化完成时的事件写在这里,如在这结束loading事件, ...
- linux时区修改为中国时区
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
- 在PyCharm 软件中设置你的项目 使用的Python版本
在PyCharm 软件中设置你的项目 使用的Python版本 python2 和 python3 有很大的不同,使用python2 编写的程序,如果使用python3 就运行不了:使用python3编 ...
- AdapterPattern(23种设计模式之一)
设计模式六大原则(1):单一职责原则 设计模式六大原则(2):里氏替换原则 设计模式六大原则(3):依赖倒置原则 设计模式六大原则(4):接口隔离原则 设计模式六大原则(5):迪米特法则 设计模式六大 ...
- protocol buffers的使用示例
protocol buffers的使用示例 如果不了解protocol buffers,可以先参看:http://blog.csdn.net/zhu_xun/article/details/19343 ...
- python3-函数的参数的四种简单用法:
def print_two(*args): arg1, arg2 = args print "arg1: %r, arg2: %r" % (arg1,arg2) ...
- windows10系统连接蓝牙鼠标自动断开解决方案
环境: Windows 10 企业版 2016 长期服务版 罗技M590 问题: 鼠标长时间未使用,会自动断开 解决步骤: 参考链接: https://zhidao.baidu.com/questio ...
- sqlserver快速删除整个表数据
--删除整个表数据 SET STATISTICS TIME ON; DECLARE @Timer DATETIME = GETDATE(); TRUNCATE TABLE LOG_DEBUG_ERRO ...
- 百度地图 JS API开发Demo01
百度地图DEMO <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http: ...