springboot log does not record exceptions
background
The springboot project is put on the server and runs. The scheduled task is interrupted during the operation. I checked the log but found no errors reported.
Running locally, I found that the console can print error messages, and the log does not record error messages.
After investigation, it was found that the error occurred in the thread pool and was not recorded in the log.
Originally used thread pool:
ExecutorService executorService = (15);
solve
New class inheritanceThreadPoolExecutor
, rewriteafterExecute
method.
@Slf4j public class TaskExecutor extends ThreadPoolExecutor { public TaskExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue) { super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue); } @Override protected void afterExecute(Runnable r, Throwable t) { (r, t); if (t != null) { ((), t); } } }
use:
ExecutorService executorService = new TaskExecutor(10, 15, 0L, , new LinkedBlockingQueue<>());
There is exception information in the log.
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.