【发布时间】:2018-08-11 17:58:21
【问题描述】:
在以下场景中,我的任务会引发异常。我只是在一个请求之后,我的池将无法处理任何进一步的请求,但它没有发生。在这种情况下线程池的行为如何?从 Pool 线程到主应用程序线程如何进行异常通信?
public class CallableClass implements Callable<String> {
@Override
public String call() throws Exception {
throw new RuntimeException();
}
}
class Test {
ExecutorService executor = Executors.newFixedThreadPool(1);
public void execute(){
try {
System.out.println(executor);
Future<String> future = executor.submit(new Task());
System.out.println(executor);
future.get();
}catch(Exception e) {
System.out.println(executor);
e.printStackTrace();
}
}
}
【问题讨论】:
标签: java multithreading threadpool executorservice threadpoolexecutor