title: Propagate Spring security Context
body: <p>I am trying to use concurrent mechanism in my Spring based web application. so that I have used the below method to use thread concept to get the employee details. but I have failed with Null pointer exception due to spring context is null on threads.</p>
  
  <p>I have used the below code:</p>
  
  <pre><code>ThreadPoolTaskExecutor threadPool = new ThreadPoolTaskExecutor();
              threadPool.setCorePoolSize(10);
              threadPool.initialize();
  
              ExecutorServiceAdapter adapter = new ExecutorServiceAdapter(threadPool);
              List&lt;Callable&lt;Employee&gt;&gt; tasks = new ArrayList&lt;Callable&lt;Employee&gt;&gt;();
  
              for (int i = 0; i &lt; employeeArr.length; i++) {
                  final int value = i;
                  tasks.add(new Callable&lt;Employee&gt;() {
                      public Employee call() throws Exception {
                          return empService.getEmployeeDetails(employeeArr[value], finalFromDate);
                      }
                  });
              }
  
  
              try {
                  List&lt;Future&lt;Employee&gt;&gt; result = adapter.invokeAll(tasks);
                  for (int i = 0; i &lt; result.size(); i++) {
                      System.out.println(result.get(i).get());
                  }
              } catch (ExecutionException ex) {
                  ex.printStackTrace();
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
  </code></pre>
  
  <p>In the "empService.getEmployeeDetails" method, I am referring the Spring context by using below code:</p>
  
  <pre><code>Authentication auth = SecurityContextHolder.getContext().getAuthentication();
      Collection&lt;GrantedAuthority&gt; authorities = auth.getAuthorities();
  </code></pre>
  
  <p>But I am getting null pointer exception when accessing the spring context.</p>
  
  <p>could anyone please help me on this?</p>