我正在使用log4j2来存储用户信息。我还将这些信息从ThreadContext复制到executorService线程池中的线程,然后再在线程中运行作业,以便它们具有相同的上下文和用户信息。
问题: 1.使用ThreadContext存储和共享用户信息是否正确? 2.与executorService线程共享此信息是否有问题?
// mdc is set in the Runnable class before submitting the job to threadPool
Map mdc = ThreadContext.getContext();
//Run method of the Runnable class
@Override
public void run() {
Map mdc = ThreadContext.getContext();
ThreadContext.putAll(mdc);
try{
// Perform operations
} finally {
ThreadContext.clearMap();
}
}