Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-2855

Managing ThreadContext across thread pool and worker threads

    XMLWordPrintableJSON

Details

    • Question
    • Status: Closed
    • Minor
    • Resolution: Information Provided
    • 2.10.0
    • None
    • API
    • None

    Description

      Hello, my team supports a spring boot rest API and we have been leveraging ThreadContext to share meta-data about our api requests to the log events we record throughout our request processing.

      Recently we had noticed that logs generated from thread-pool or worker threads do not share this context and the contextMap would be empty.

      For that reason we enabled

      isThreadContextMapInheritable=true
      

      This indeed shares the context to child threads, but now we are having an issue where the contextMap is bleeding into the logs of other API requests. Please advise how to better tune this functionality.

      Below is a snippet of code where we build the ThreadContext in the API resource and attempt to clear it before another request comes in.

      try {
         ThreadContext.put("id", request.getId());
         <..more context..>
         return evaluate(request
      } finally { ThreadContext.clearAll(); }
      

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            peterpod Peter Podniesinski
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: