Java多线程问题--线程运行时出现异常的解决办法

Posted 二云

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java多线程问题--线程运行时出现异常的解决办法相关的知识,希望对你有一定的参考价值。

private static final ThreadPoolExecutor executor = new ThreadPoolExecutor(32, 128, 120, TimeUnit.SECONDS,
new LinkedBlockingQueue<>(512),
r -> {
Thread t = new Thread(r);
t.setUncaughtExceptionHandler((th, e) ->
logger.error(LogBuilder.log("ThreadPoolExecutor", "uncaught exception," + th.getName()), e)
);
t.setName("th" + t.getId());
return t;
},
(r, exec) -> {
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
throw new RejectedExecutionException("Task " + r.toString() +
" rejected from " +
e.toString());
}

exec.getQueue().add(r);
});

以上是关于Java多线程问题--线程运行时出现异常的解决办法的主要内容,如果未能解决你的问题,请参考以下文章