public static void main(String[] args) {
ExecutorService threadPool = Executors.newFixedThreadPool(10);
Thread thread = new Thread(() -> {
Thread.currentThread().setUncaughtExceptionHandler((t, e) -> {
// 异常处理的地方,t 代表当前线程,e 代表异常
});
// 以下是线程任务代码
System.out.println("1");
});
for (int i = 0; i < 10; i++) {
threadPool.execute(thread);
}
}
网友评论