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实 ...
随机推荐
- TextView下划线,部分文字并响应点击事件(SpannableString)
TextView useInfo = (TextView) findViewById(R.id.info); useInfo.setText("开始即表示您同意遵守"); Stri ...
- JAVA input/output 流层次关系图
在java中,input和output流种类繁多,那么它们之间是否有关系呢?答案是肯定的,其中使用到了设计模式,装饰模式 下图来自于HEAD FIRST 设计模式 装饰模式一章 下图来自网络博客:ht ...
- 报错:空指针java.lang.NullPointerException 原因 Action层 private UserService userservice 上未加@Autowire注解
java.lang.NullPointerException at com.itheima.test.Test2.fun1(Test2.java:18) at sun.reflect.NativeMe ...
- Elasticsearch - glossary
From http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/glossary.html glossary of ...
- wpf仿qq边缘自动停靠,支持多屏
wpf完全模仿qq边缘自动隐藏功能,采用鼠标钩子获取鼠标当前状态,在通过当前鼠标的位置和点击状态来计算是否需要隐藏. 以下是实现的具体方法: 一.鼠标钩子实时获取当前鼠标的位置和点击状态 /// &l ...
- (华为机试大备战)java。多了解了解最常用的那个类库的方法对处理字符串的方法
1.常考字符串处理:对处理字符串的方法. (a)统计字符串中特定字符的个数. 2.郭靖考了一道二维数组?? 3.多了解了解最常用的那个类库的方法.
- 715B Complete The Graph
传送门 题目大意 给出一个图,一些边带权,另一些边等待你赋权(最小赋为1).请你找到一种赋权方式,使得 s 到 t 的最短路为 L n ≤ 1e3 ,m ≤ 1e4 ,L ≤ 1e9 分析 二分所有边 ...
- Swingr的JTextField、JPasswordField设置圆角输入框
方法1:定义Border,然后给JTextField设置即可 摘自并整理:https://blog.csdn.net/u012093968/article/details/39316679 最好添加这 ...
- C++面试笔记--字符串
基本上求职者进行笔试没有不考字符串的.字符串也是一种相对简单的数据结构,容易被考.事实上,字符创也是一个考验程序猿编程规范和编程习惯的重要考点. 1.替换空格:实现一个函数,把字符串中的每个空格替换成 ...
- How a web page loads
The major web browsers load web pages in basically the same way. This process is known as parsing an ...