【发布时间】:2015-04-16 14:06:06
【问题描述】:
我通过使用 Executor Service 创建 3 个线程(扩展 Runnable)并提交它们来执行 Main 类中的三个任务。如下:
ExecutorService executor = Executors
.newFixedThreadPool(3);
A a= new A();
B b= new B();
C c= new C();
/**
* Submit/Execute the jobs
*/
executor.execute(a);
executor.execute(b);
executor.execute(c);
try {
latch.await();
} catch (InterruptedException e) {
//handle - show info
executor.shutdownNow();
}
当线程中发生异常时,我会捕获它并执行 System.exit(-1)。但是,如果发生任何异常,我需要返回主类并在那里执行一些语句。这该怎么做?我们可以在没有 FutureTask 的情况下从这些线程返回一些东西吗?
【问题讨论】:
标签: java multithreading executorservice threadpoolexecutor