title: Correct way to use EJB Asynchronous methods
body: <p>I have two tasks that I need to perform say <code>task1</code> and <code>task2</code> which are a part of same business process. I have to give response to the end user when <code>task1</code> completes so it's response time have to be minimized.</p>
  
  <p>My current approach is to perform <code>task1</code> and as soon as <code>task1</code> is finished, invoke <code>task2</code> method asynchronously. <code>task2</code> is complicated and it's response time is out of my control as it has some external dependency.</p>
  
  <pre><code>@Stateless
  public class SessionBean1 {
  
      @Inject
      SessionBean2 sessionBean2;
  
      public void doTask1(){
          // task one stuff
          sessionBean2.doTask2();
      }
  
  }
  
  
  
  @Stateless
  public class SessionBean2 {
  
      @Asynchronous
      public void doTask2(){
          // do task2 stuff
      }
  
  }
  </code></pre>
  
  <p>In websphere 8.0 (the EJB container in use) synchronous methods and asynchronous methods are run by different thread pools. </p>
  
  <p>My initial assumption was that even if <code>task2</code> is performing badly, <code>task1</code> would have no impact, but sadly that's not true. </p>
  
  <p>If <code>task2</code> is performing badly, all threads from asynchronous thread pool will be occupied. This will cause <code>task1</code> to wait for asynchronous threads to be free and hence <code>task1</code> has impact.</p>
  
  <p>The message in websphrere server logs : 
  <code>The request buffer for thread pool WorkManager.WebSphere_EJB_Container_AsynchMethods_Internal_WorkManager has reached its capacity</code></p>
  
  <p>My question is what would be a proper way to achieve what I'm trying to achieve here.</p>