1

Is it safe to Use MDC to pass column values and xmls dynamically to a preparedstatement in log4j.xml. If yes, then how and when can i clear it to avoid memory leaks.

FYI - many threads are going to use my log4j simultaneously.

user837593
  • 337
  • 1
  • 5
  • 25

1 Answers1

0

If your concern about safty is for concurrency, then I would say your information is totally safe. For reference you can check logback website

A copy of the mapped diagnostic context can not always be inherited by worker threads from the initiating thread. This is the case when java.util.concurrent.Executors is used for thread management. For instance, newCachedThreadPool method creates a ThreadPoolExecutor and like other thread pooling code, it has intricate thread creation logic.

We put the values in the MDC when a request is to be processed(generally in the ServletFilter in case of J2EE applications) and we always remove the values when the request processing is about to complete.

Ram Dutt Shukla
  • 1,351
  • 7
  • 28
  • 55