The service receives tasks from outside and runs them in a separate thread.
A thread pool is used.
For logging, slf4j.MDC is used with the task id saved.
MDC.put ("Session", String.valueOf (task.getId ()));
I understand correctly that when using a thread pool, there is no need to remove data from the MDC.
That is, you can add data without deleting it, and there will be no memory leak?
Those. after using it in a stream, can we not delete data like this?
MDC.remove ("Session");
Because a thread pool is used, with each new thread, the old data will simply be overwritten, and there will be no memory overflow. Ie it is not necessary. Do I get it right?
question from:
https://stackoverflow.com/questions/65914576/slf4j-mdc-thread-pool-memory-leak 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…