package com.xqx.test;
import java.util.concurrent.CountDownLatch;
/***
* 测试线程取消--2
* @author ruihu
*
*/
public class ExportTest {
public static void main(String[] args) {
CountDownLatch lock = new CountDownLatch(1);//创建锁
//1、执行
ExportRunnable runnable = new ExportRunnable(lock);
Thread thread = new Thread(runnable);
thread.start();
try {
System.out.println("等待中。。。");
lock.await();//阻塞等待执行完毕后执行
System.out.println("执行完毕。。");
} catch (InterruptedException e) {
e.printStackTrace();
}
//2、继续执行后面代码
if(!runnable.isFinished()){
System.out.println("没有取消,继续执行后续操作");
}else{
System.out.print("已取消,返回警告");
}
//取消当前线程
runnable.setCanceled(true);
}
}
最近下载更多
cc900118 LV17
2021年9月17日
lironggang LV38
2019年7月3日
1792312911 LV17
2018年6月26日
15735184511 LV7
2018年1月4日
你高冷 LV12
2017年10月12日
248196826 LV13
2016年11月26日
好脑壳 LV16
2016年11月9日
xuexizhuanyong23 LV16
2016年9月4日

最近浏览