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的更多相关文章

  1. Thread之八:interrupt中断

    Java中断机制是一种协作机制,也就是说通过中断并不能直接终止另一个线程,它只是要求被中断线程在合适的时机中断自己,这需要被中断的线程自己处理中断.这好比是家里的父母叮嘱在外的子女要注意身体,但子女是 ...

  2. Java中的Interrupt使用

    初心 用interrupt中断程序 初步实现 public class InterruptionInJava implements Runnable{ @Override public void ru ...

  3. Java并发分析—Lock

    1.Lock 和 Condition 当使用synchronied进行同步时,可以在同步代码块中只用常用的wait和notify等方法,在使用显示锁的时候,将通过Condition对象与任意Lock实 ...

随机推荐

  1. Oracle pl/sql 记录、表类型

    一.PL/SQL记录 定义: TYPE <类型名> IS RECORD <列名1 类型1,列名2 类型2,...列名n 类型n,> [NOT NULL] <列的类型> ...

  2. springboot启动过程(2)-run方法

    1 springApplication的run run方法主要是用于创造spring容器ConfigurableApplicationContext对象. public ConfigurableApp ...

  3. SQl Server 表链接查询

    之前漏下了,这里补一偏 select * from student,score ——笛卡尔积 可以想想成c#里面的多维函数的样子,打印时每一张表的每一条数据都会连带着第二张表的所有数据 两个表的连接: ...

  4. Visual Studio Command Prompt 工具配置方法

    有时候,我们无法找到Visual Studio Command Prompt,需要手动配置 打开 Visual studio2015,选择  "工具"—>"外部工具 ...

  5. IFC数据模型在三维引擎中模拟

  6. 提取a标签的链接文字

    在seg上看到一个问题 <a href="http://www.abc.com/thread-4131866-1-1.html" class="s xst" ...

  7. Java Swing 创建转圈的进度提示框

    Java Swing 创建转圈的进度提示框 摘自 https://blog.csdn.net/nihaoqiulinhe/article/details/52439486 置顶2016年09月05日 ...

  8. wordCount总结

    1.github地址:https://github.com/husterSyy/SoftTest 2.PSP表格   psp 2.1 psp阶段 预估耗时(分钟) 实际耗时(分钟) Planning ...

  9. 多线程学习-基础( 十)一个synchronized(){/*代码块*/}简单案例分析

    一.提出疑惑 上一篇文章中,分析了synchronized关键字的用法.但是好像遗漏了一种情况. 那就是: synchronized(obj){/*同步块代码*/} 一般有以下几种情况: (1)syn ...

  10. WebGoat系列实验Access Control Flaws

    WebGoat系列实验Access Control Flaws Using an Access Control Matrix 在基于角色的访问控制策略中,每个角色都代表了一个访问权限的集合.一个用户可 ...