title: How can I have @Async work on 2 different threads for 2 different methods in Spring.?
body: <p>In my application I have 2 <code>@Async</code> methods: one for auditing purposes and another for updation of some maps in 2 entirely different beans, called from different beans but at same time. One from Audit listener and other from a controller.</p>
  
  <p>My problem is that both of them run in a single thread, i.e first audit runs and then in the same thread those maps are created. So, if audit throws some exception, maps wont be created, or maps throw an error, audit wont get recorded. </p>
  
  <p>Is there any way, I can have these 2 methods run in different Async threads.</p>
  
  <p>Method1:</p>
  
  <pre><code>@Async(value="myExecutor")
  @Transactional(propagation = Propagation.REQUIRES_NEW)
  public void regenerateZoneMapAsync(DemandSource ds) {
      System.out.println("\n\n********************Current Thread in Async Class*****************" + Thread
              .currentThread());
      regenerateZmFilesByDs(ds);
      System.out.println("\n\n*********Current Thread********" + Thread.currentThread());
  }
  </code></pre>
  
  <p>Method2:</p>
  
  <pre><code>@Async(value="myExecutor")
  @Transactional(propagation = Propagation.REQUIRES_NEW)
  public void callAudit(DemandSource ds) {
      System.out.println("\n\n************Current Thread in Audit Class*********" + Thread
              .currentThread());
      callAudit(ds);
      System.out.println("\n\n***********Current Thread********" + Thread.currentThread());
  }
  </code></pre>
  
  <p>println has been added for my own clarity, to know which thread is been executed. I am new to both, multithreading and Spring.</p>
  
  <p>My config class has </p>
  
  <pre><code>&lt;task:annotation-driven executor="myExecutor"/&gt; 
  &lt;task:executor id="myExecutor" pool-size="5"/&gt; 
  </code></pre>
  
  <p>After adding above configuration with <code>@Async(value="myExecutor")</code> my code has stopped working altogether, By this I mean,bean in which <code>regenerateZoneMapAsync()</code> has been defined, is not called from my calling bean, some proxy issue arises.</p>
  
  <p>Edit:</p>
  
  <p>One thing that comes in my mind is can it be possible that Audit thread completes its processing and send the thread back to pool, and then map picks the same thread and starts its processing.</p>
  
  <p>Basically I want that if audit throws any error, and roll backs map updation should still happen.</p>