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);
});


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM