title: Destroying asnync proxy of SLSB by JBoss
body: <p>In my application based on EJB3.0 and JBoss5 I use async proxy from JBoss AsyncUtils.
  Stateful bean <strong>ComputerBean</strong> dispatches work to stateless pooled <strong>ProcessorBean</strong>(s). I built counter into ProcessorBeans to print out how many of them is currently instantiated. Here is the code:</p>
  
  <pre><code>@Stateful
  public class ComputerBean implements ComputerRemote {
  
      @EJB
      private ProcessorLocal processor;
  
      public void startComputations() {
          Random r = new Random();
          while(true) {
              AsyncUtils.mixinAsync(processor).compute(r.nextInt());
          }
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>@Stateless
  public class ProcessorBean implements ProcessorLocal {
  
      private static int COUNTER = 0;
  
      @PostConstruct
      public void init() {
          System.out.println("constructing");
          COUNTER++;
      }
  
      @PreDestroy
      public void destroy() {
          System.out.println("destroying");
          COUNTER--;
      } 
  
      public void compute(int i) {
          System.out.println("----------------&gt; " + COUNTER);
  
          // some dummy computations - it's here only in order to take some time
          double d = 0.3;
          for (int j=0; j&lt;100; j++) {
              d+= 0.2 % 4 + i;
          }
      }
  }
  </code></pre>
  
  <p>Tracking console on which JBoss runs I noticed that number of SLSBeans is increased (due to higher load), but it never goes down, even if i stop computations for 20 minutes, and then restarts. </p>
  
  <p>It's a dummy example, but I want to use this mechanism in a more complex system, so I have to be sure that I know exactly how it works. Did i do something wrong? Why SLSBeans counter never goes down? </p>
  
  <p>Thanks in advance,
  Piotr</p>