title: Including the ThreadContext when writing log4j2 logs via a Java Static method - Is it thread safe?
body: <p>In a web service application I am using a static method to set log4j ThreadContext variables for logging purposes as below,</p>
  
  <pre><code>public static void setLogParams(String company_id, String userId) {
      ThreadContext.put("company_id_val", company_id);
      ThreadContext.put("user_id_val", userId);
  }
  </code></pre>
  
  <p>Each and every web service requests will be call above method initially and then <code>loj4j Logger object</code> will use for do the rest.  Above given values are not same every time and may vary request to request.</p>
  
  <p>My question: Is above scenario is thread safe? Will different web service requests share the same <code>company_id</code> and <code>user_id</code> since both of these parameters are holding same references? Then it will be confusing. Should I use a non-static method instead? </p>
  
  <p>I did gone through the similar question below</p>
  
  <p><a href="https://stackoverflow.com/questions/5173399/are-non-synchronised-static-methods-thread-safe-if-they-dont-modify-static-clas">Are non-synchronised static methods thread safe if they don&#39;t modify static class variables?</a> </p>
  
  <p>But I need to clarify this.</p>