如果任何提交的线程抛出异常,则不会返回异常。
我想为我的项目编写一段代码,如果任何线程执行失败,它应该在那里抛出异常并且它应该停止所有正在运行和计划的线程。
ExecutorService executorService = Executors.newFixedThreadPool(10);
for (int i = 0; i < 10; i++) {
Thread t = new Thread(new MyObject());
executorService.submit(t);
}
Run Code Online (Sandbox Code Playgroud)
我这样写 MyObject ..,
public class MyObject implements Runnable {
public void run() {
throw new NullPointerException("Sample NullPointerException");
}
}
Run Code Online (Sandbox Code Playgroud)
这是我目标的正确实现吗......????我想实现那个目标,请给我一些指示。
提前致谢....!!
java multithreading exception-handling threadpool threadpoolexecutor