1 22 package org.jboss.ejb3.test.strictpool; 23 24 import javax.annotation.Resource; 25 import javax.ejb.EJBException ; 26 import javax.ejb.Remote ; 27 import javax.ejb.SessionContext ; 28 import javax.ejb.Stateless ; 29 import org.jboss.annotation.ejb.PoolClass; 30 31 32 37 @Stateless 38 @PoolClass (value=org.jboss.ejb3.StrictMaxPool.class, maxSize=StrictlyPooledSessionBean.maxActiveCount, timeout=10000) 39 @Remote (StrictlyPooledSession.class) 40 public class StrictlyPooledSessionBean implements StrictlyPooledSession 41 { 42 43 public static final int maxActiveCount = 5; 44 45 private static int activeCount; 46 47 private SessionContext ctx; 48 49 @Resource public void setSessionContext(SessionContext ctx) 50 { 51 System.out.println("setSessionContext()"); 52 this.ctx = ctx; 53 } 54 55 public void methodA() 56 { 57 int count = incActiveCount(); 58 System.out.println("Begin methodA, activeCount="+count+", ctx="+ctx); 59 try 60 { 61 if( count > maxActiveCount ) 62 { 63 String msg = "IllegalState, activeCount > maxActiveCount, " 64 + count + " > " + maxActiveCount; 65 throw new EJBException (msg); 66 } 67 Thread.currentThread().sleep(1000); 69 } 70 catch(InterruptedException e) 71 { 72 } 73 finally 74 { 75 count = decActiveCount(); 76 System.out.println("End methodA, activeCount="+count+", ctx="+ctx); 77 } 78 } 79 80 private static synchronized int incActiveCount() 81 { 82 return activeCount ++; 83 } 84 private static synchronized int decActiveCount() 85 { 86 return activeCount --; 87 } 88 89 } 90 | Popular Tags |