title: How to get thread ID in Java
body: <p>I can specify log4j formatter as follows to print current thread id in spring mvc application</p>
  
  <pre><code>log4j.appender.FILE.layout.ConversionPattern=%d{ISO8601} %p %t %c - %m%n
  </code></pre>
  
  <p>How do I programmatically get current thread id in my spring application. More precisely, I want to get current thread id in an aspect that intercepts controller methods. My aspect is as follows:</p>
  
  <pre><code>@Configurable
  @Aspect
  public class TimingAspect {
  
      @Autowired
      private HttpServletRequest httpServletRequest;
  
      //Generic performance logger for any mothod
      private Object logPerfomanceInfo(ProceedingJoinPoint joinPoint) {
         // do something with thread id
         // do something with httprequest
          ...
      }
  
      // Performance info for API calls
      @Around("execution(* package.controller.*.*(..))")
      public Object logAroundApis(ProceedingJoinPoint joinPoint) throws Throwable {
          return logPerfomanceInfo(joinPoint);
      }
  }
  </code></pre>