1、调用超过两秒后,返回,但继续执行子线程
@Test
public void test04 () throws Exception{
System.out.println("主线程开始。。。。。111");
Callable task = new Callable() {
@Override
public String call() throws InterruptedException {
System.out.println("子线程开始。。。。。111");
Thread.sleep(4000);
System.out.println("子线程开始。。。。。2222");
return "完成子线程";
}
};
Thread.sleep(5000);
System.out.println("主线程开始。。。。。2222");
Future future = executorService.submit(task);
try {
future.get(2, TimeUnit.SECONDS);
} catch (Exception e) {
System.out.println("超时返回临时");
}
}