当前位置:网站首页>Child parent thread interaction
Child parent thread interaction
2022-07-28 05:44:00 【Little madman green】
public static void main(String[] args) throws Exception {
FutureTask futureTask1 = new FutureTask(new Callable<String>() {
@Override
public String call() throws Exception {
Thread.sleep(3000);
System.out.println(Thread.currentThread().getName() + "--------- Ha ha ha 1------");
return Thread.currentThread().getName() + "---------hello 1------";
}
});
FutureTask futureTask2 = new FutureTask(new Callable<String>() {
@Override
public String call() throws Exception {
Thread.sleep(3000000);
System.out.println(Thread.currentThread().getName() + "--------- Ha ha ha 2------");
// throw new Exception();
return "test2";
}
});
new Thread(futureTask1).start();
new Thread(futureTask2).start();
System.out.println(futureTask1.get());
try {
futureTask2.get(1,TimeUnit.NANOSECONDS);
}catch (TimeoutException e) {
futureTask2.cancel(true);
e.printStackTrace();
}catch (Exception e){
System.out.println(e.getMessage());
}
}
Running results
Thread-0--------- Ha ha ha 1------
Thread-0---------hello 1------
java.util.concurrent.TimeoutException
at java.util.concurrent.FutureTask.get(FutureTask.java:205)
at question.ExceptionInChildThread.main(ExceptionInChildThread.java:79)
边栏推荐
- 冶金物理化学复习 --- 复杂反应的速率方程
- SVG了解与绘图应用
- 冶金物理化学复习 --- 化学反应动力学基础
- Openjudge: find the first character that appears only once
- JUC notes
- latex和word之间相互转换
- openjudge:过滤多余的空格
- [MySQL] solve the problem of MySQL time zone and 8-hour difference in database time
- When using deep learning training image, the image is too large for segmentation training prediction
- The essence of dynamic convolution
猜你喜欢

对极大似然估计、梯度下降、线性回归、逻辑回归的理解

Distillation model diagram

Review of Metallurgical Physical Chemistry - gas liquid phase reaction kinetics

Advanced multi threading: the underlying principle of synchronized, the process of lock optimization and lock upgrade

visio如何快速生成相同的图案,生成图像矩阵

GET与POST区别

ECCV22 最新54篇论文主图整理

Invalid bound statement (not found): com.exam.mapper.UserMapper.findbyid

顺序表的增删查改

Event_looop-事件循环机制
随机推荐
How Visio can quickly generate the same pattern and image matrix
The essence of dynamic convolution
JUC notes
The Monte Carlo method solves the PI and draws points with turtle, and completes the progress bar problem
A file upload tool website written by individuals
Event_looop-事件循环机制
Custom JSON return data
动态卷积的本质
es6新增数据类型--->Symbol、Map、Set
openjudge:矩阵乘法
五子棋优化版
排序之插入排序
Openjudge: count the number of numeric characters
Invalid bound statement (not found): com.exam.mapper.UserMapper.findbyid
latex和word之间相互转换
环形链表问题
记录某某小卢的第一篇文章
openjudge:病人排队
Merge two ordered arrays of order table OJ
Oracle view lock table statement and unlocking method