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. WCF客户端调用并行最大同时只支持两个请求

    做项目的时候发现 频繁调用WCF服务时 明明一次性发起了几十个请求 而在服务端记录的日志却显示出现了排队的迹象 并且都是最大并发数为2 在网上狂搜 大家给出来的解决方法都是增加web.config里面 ...

  2. Ros学习——创建程序包

      1.程序包 一个程序包要想称为catkin程序包必须符合以下要求: 该程序包必须包含catkin compliant package.xml文件 这个package.xml文件提供有关程序包的元信 ...

  3. git安装、git和GitHub的配合使用、git和码云的配合使用

    1 git安装请参见廖雪松的git教程前面几节 点击前往 2 git速成之基本命令 点击前往 3 git 和 GitHub 配合使用之基础 点击前往 4 git 和 GitHub 配合使用之进阶 点击 ...

  4. Tensorflow手写数字识别训练(梯度下降法)

    # coding: utf-8 import tensorflow as tffrom tensorflow.examples.tutorials.mnist import input_data #p ...

  5. ZROI2018提高day5t1

    传送门 分析 我们不难将条件转换为前缀和的形式,即 pre[i]>=pre[i-1]*2,pre[i]>0,pre[k]=n. 所以我们用dp[i][j]表示考虑到第i个数且pre[i]= ...

  6. Django框架 之 URLconf

    Django框架 之 URLconf 浏览目录 URL 摘要 Django如何处理一个请求 反向解析URL name模式 namespace模式 一.URL 1.摘要 我们要在Django项目中为应用 ...

  7. java获取本机名称、IP、MAC地址和网卡名称

    java获取本机名称.IP.MAC地址和网卡名称 摘自:https://blog.csdn.net/Dai_Haijiao/article/details/80364370 2018年05月18日 1 ...

  8. JavaScript中的Array.prototype.slice.call()方法学习

    JavaScript中的Array.prototype.slice.call(arguments)能将有length属性的对象转换为数组(特别注意: 这个对象一定要有length属性). 但有一个例外 ...

  9. 回溯法和DFS leetcode Combination Sum

    代码: 个人浅薄的认为DFS就是回溯法中的一种,一般想到用DFS我们脑中一般都有一颗解法树,然后去按照深度优先搜索去寻找解.而分支界限法则不算是回溯,无论其是采用队列形式的还是优先队列形式的分支界限法 ...

  10. sql删除语句几种方法说明

    delete from 'tableName: DELETE 语句每次删除一行,并在事务日志中为所删除的每行记录一项.(相当于把房子里家具全丢了,但为了纪念原先的家具,所以原先放家具的那块地以后不再放 ...