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 36 @Stateless 37 @PoolClass(value=org.jboss.ejb3.test.strictpool.BogusPool.class, maxSize=0, timeout=0) 38 @Remote (StrictlyPooledSession.class) 39 public class OverrideStrictlyPooledSessionBean implements StrictlyPooledSession 40 { 41 42 public static final int maxActiveCount = 5; 43 44 private static int activeCount; 45 46 private SessionContext ctx; 47 48 @Resource public void setSessionContext(SessionContext ctx) 49 { 50 System.out.println("setSessionContext()"); 51 this.ctx = ctx; 52 } 53 54 public void methodA() 55 { 56 int count = incActiveCount(); 57 System.out.println("Begin methodA, activeCount="+count+", ctx="+ctx); 58 try 59 { 60 if( count > maxActiveCount ) 61 { 62 String msg = "IllegalState, activeCount > maxActiveCount, " 63 + count + " > " + maxActiveCount; 64 throw new EJBException (msg); 65 } 66 Thread.currentThread().sleep(1000); 68 } 69 catch(InterruptedException e) 70 { 71 } 72 finally 73 { 74 count = decActiveCount(); 75 System.out.println("End methodA, activeCount="+count+", ctx="+ctx); 76 } 77 } 78 79 private static synchronized int incActiveCount() 80 { 81 return activeCount ++; 82 } 83 private static synchronized int decActiveCount() 84 { 85 return activeCount --; 86 } 87 88 } 89 | Popular Tags |