[jboss-cvs] JBossAS SVN: r65604 - in projects/ejb3/trunk: pool and 22 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Sep 25 14:17:06 EDT 2007


Author: wolfc
Date: 2007-09-25 14:17:06 -0400 (Tue, 25 Sep 2007)
New Revision: 65604

Added:
   projects/ejb3/trunk/pool/
   projects/ejb3/trunk/pool/.classpath
   projects/ejb3/trunk/pool/.project
   projects/ejb3/trunk/pool/.settings/
   projects/ejb3/trunk/pool/.settings/org.eclipse.jdt.core.prefs
   projects/ejb3/trunk/pool/pom.xml
   projects/ejb3/trunk/pool/src/
   projects/ejb3/trunk/pool/src/main/
   projects/ejb3/trunk/pool/src/main/java/
   projects/ejb3/trunk/pool/src/main/java/org/
   projects/ejb3/trunk/pool/src/main/java/org/jboss/
   projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/
   projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/
   projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/Pool.java
   projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/StatelessObjectFactory.java
   projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/inifinite/
   projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/inifinite/InfinitePool.java
   projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/strictmax/
   projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/strictmax/StrictMaxPool.java
   projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/threadlocal/
   projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/threadlocal/ThreadLocalPool.java
   projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/threadlocal/WeakThreadLocal.java
   projects/ejb3/trunk/pool/src/test/
   projects/ejb3/trunk/pool/src/test/java/
   projects/ejb3/trunk/pool/src/test/java/org/
   projects/ejb3/trunk/pool/src/test/java/org/jboss/
   projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/
   projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/test/
   projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/test/pool/
   projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/test/pool/common/
   projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/test/pool/common/MockBean.java
   projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/test/pool/common/MockFactory.java
   projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/test/pool/infinite/
   projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/test/pool/infinite/InfinitePoolUnitTestCase.java
   projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/test/pool/strictmax/
   projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/test/pool/strictmax/StrictMaxUnitTestCase.java
   projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/test/pool/threadlocal/
   projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/test/pool/threadlocal/ThreadLocalPoolUnitTestCase.java
Log:
Initial release


Property changes on: projects/ejb3/trunk/pool
___________________________________________________________________
Name: svn:ignore
   + eclipse-target
target


Added: projects/ejb3/trunk/pool/.classpath
===================================================================
--- projects/ejb3/trunk/pool/.classpath	                        (rev 0)
+++ projects/ejb3/trunk/pool/.classpath	2007-09-25 18:17:06 UTC (rev 65604)
@@ -0,0 +1,15 @@
+<classpath>
+  <classpathentry kind="src" path="src/main/java"/>
+  <classpathentry kind="src" path="src/test/java" output="eclipse-target/tests-classes"/>
+  <classpathentry kind="output" path="eclipse-target/classes"/>
+  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+  <classpathentry kind="var" path="M2_REPO/apache-slide/webdavlib/2.0/webdavlib-2.0.jar"/>
+  <classpathentry kind="var" path="M2_REPO/oswego-concurrent/concurrent/1.3.4/concurrent-1.3.4.jar"/>
+  <classpathentry kind="var" path="M2_REPO/apache-log4j/log4j/1.2.8/log4j-1.2.8.jar"/>
+  <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar" sourcepath="M2_REPO/junit/junit/3.8.1/junit-3.8.1-sources.jar"/>
+  <classpathentry kind="var" path="M2_REPO/apache-httpclient/commons-httpclient/2.0.2/commons-httpclient-2.0.2.jar"/>
+  <classpathentry kind="var" path="M2_REPO/jboss/jboss-logging-spi/2.0.2.GA/jboss-logging-spi-2.0.2.GA.jar" sourcepath="M2_REPO/jboss/jboss-logging-spi/2.0.2.GA/jboss-logging-spi-2.0.2.GA-sources.jar"/>
+  <classpathentry kind="var" path="M2_REPO/apache-xerces/xml-apis/2.7.1/xml-apis-2.7.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/jboss/jboss-logging-log4j/2.0.2.GA/jboss-logging-log4j-2.0.2.GA.jar" sourcepath="M2_REPO/jboss/jboss-logging-log4j/2.0.2.GA/jboss-logging-log4j-2.0.2.GA-sources.jar"/>
+  <classpathentry kind="var" path="M2_REPO/jboss/jboss-common-core/2.0.2.GA/jboss-common-core-2.0.2.GA.jar" sourcepath="M2_REPO/jboss/jboss-common-core/2.0.2.GA/jboss-common-core-2.0.2.GA-sources.jar"/>
+</classpath>
\ No newline at end of file

Added: projects/ejb3/trunk/pool/.project
===================================================================
--- projects/ejb3/trunk/pool/.project	                        (rev 0)
+++ projects/ejb3/trunk/pool/.project	2007-09-25 18:17:06 UTC (rev 65604)
@@ -0,0 +1,13 @@
+<projectDescription>
+  <name>jboss-ejb3-pool</name>
+  <comment>JBoss EJB 3 Pool classes for stateless beans</comment>
+  <projects/>
+  <buildSpec>
+    <buildCommand>
+      <name>org.eclipse.jdt.core.javabuilder</name>
+    </buildCommand>
+  </buildSpec>
+  <natures>
+    <nature>org.eclipse.jdt.core.javanature</nature>
+  </natures>
+</projectDescription>
\ No newline at end of file

Added: projects/ejb3/trunk/pool/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- projects/ejb3/trunk/pool/.settings/org.eclipse.jdt.core.prefs	                        (rev 0)
+++ projects/ejb3/trunk/pool/.settings/org.eclipse.jdt.core.prefs	2007-09-25 18:17:06 UTC (rev 65604)
@@ -0,0 +1,5 @@
+#Tue Sep 25 15:10:22 CEST 2007
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5

Added: projects/ejb3/trunk/pool/pom.xml
===================================================================
--- projects/ejb3/trunk/pool/pom.xml	                        (rev 0)
+++ projects/ejb3/trunk/pool/pom.xml	2007-09-25 18:17:06 UTC (rev 65604)
@@ -0,0 +1,35 @@
+<!-- 
+  vi:ts=2:sw=2:expandtab 
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <groupId>org.jboss.ejb3</groupId>
+    <artifactId>jboss-ejb3</artifactId>
+    <version>0.11.0-SNAPSHOT</version>
+    <relativePath>../build/pom.xml</relativePath>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>jboss-ejb3-pool</artifactId>
+  <packaging>jar</packaging>
+  <name>JBoss EJB 3 Pool</name>
+  <url>http://www.jboss.org</url>
+  <description>JBoss EJB 3 Pool classes for stateless beans</description>
+  
+  <dependencies>
+    <dependency>
+      <groupId>jboss</groupId>
+      <artifactId>jboss-logging-log4j</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>jboss</groupId>
+      <artifactId>jboss-logging-spi</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+</project>


Property changes on: projects/ejb3/trunk/pool/pom.xml
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/Pool.java
===================================================================
--- projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/Pool.java	                        (rev 0)
+++ projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/Pool.java	2007-09-25 18:17:06 UTC (rev 65604)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.pool;
+
+/**
+ * A pool of stateless objects.
+ * 
+ * A pool is linked to an object factory. How this link is established
+ * is left beyond scope.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface Pool<T>
+{
+   /**
+    * Discard an object. This will be called
+    * in case of a system exception.
+    * 
+    * @param obj    the object
+    */
+   void discard(T obj);
+   
+   /**
+    * Get the an object from the pool. This will mark
+    * the object as being in use.
+    * 
+    * @return       the object
+    */
+   T get();
+   
+   /**
+    * Release the object from use.
+    * 
+    * @param obj    the object
+    */
+   void release(T obj);
+   
+   /**
+    * Remove the specified object from the pool.
+    * 
+    * @param key    the identifier of the object
+    */
+   //void remove(Object key);
+   
+   /**
+    * Start the pool.
+    */
+   void start();
+   
+   /**
+    * Stop the pool.
+    */
+   void stop();
+
+}


Property changes on: projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/Pool.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/StatelessObjectFactory.java
===================================================================
--- projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/StatelessObjectFactory.java	                        (rev 0)
+++ projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/StatelessObjectFactory.java	2007-09-25 18:17:06 UTC (rev 65604)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.pool;
+
+/**
+ * Creates and destroys stateless objects.
+ * 
+ * The object returned by create has dependencies injected. The PostConstruct
+ * callback, if defined, has been called.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface StatelessObjectFactory<T>
+{
+   /**
+    * Creates a new stateless object by calling it's empty constructor,
+    * do injection and calling post-construct.
+    * 
+    * @return
+    */
+   T create();
+   
+   /**
+    * Perform any cleanup actions on the object, such as
+    * calling the pre-destroy callback.
+    * 
+    * @param obj    the object
+    */
+   void destroy(T obj);
+}


Property changes on: projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/StatelessObjectFactory.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/inifinite/InfinitePool.java
===================================================================
--- projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/inifinite/InfinitePool.java	                        (rev 0)
+++ projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/inifinite/InfinitePool.java	2007-09-25 18:17:06 UTC (rev 65604)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.pool.inifinite;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.ejb3.pool.Pool;
+import org.jboss.ejb3.pool.StatelessObjectFactory;
+
+/**
+ * A pool that has no constraints.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class InfinitePool<T> implements Pool<T>
+{
+   private StatelessObjectFactory<T> factory;
+   private Set<T> active = new HashSet<T>();
+   
+   public InfinitePool(StatelessObjectFactory<T> factory)
+   {
+      assert factory != null : "factory is null";
+      
+      this.factory = factory;
+   }
+   
+   public void discard(T obj)
+   {
+      throw new RuntimeException("NYI");
+   }
+
+   public T get()
+   {
+      T obj = factory.create();
+      synchronized (active)
+      {
+         active.add(obj);
+      }
+      return obj;
+   }
+
+   public void release(T obj)
+   {
+      synchronized (active)
+      {
+         boolean contains = active.remove(obj);
+         if(!contains)
+            throw new IllegalArgumentException(obj + " is not of this pool");
+      }
+      factory.destroy(obj);
+   }
+
+   public void start()
+   {
+      // TODO Auto-generated method stub
+
+   }
+
+   public void stop()
+   {
+      // TODO: this is a bit wicked
+      for(T obj : active)
+      {
+         factory.destroy(obj);
+      }
+      active.clear();
+   }
+
+}


Property changes on: projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/inifinite/InfinitePool.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/strictmax/StrictMaxPool.java
===================================================================
--- projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/strictmax/StrictMaxPool.java	                        (rev 0)
+++ projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/strictmax/StrictMaxPool.java	2007-09-25 18:17:06 UTC (rev 65604)
@@ -0,0 +1,117 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.pool.strictmax;
+
+import java.util.LinkedList;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+
+import org.jboss.ejb3.pool.Pool;
+import org.jboss.ejb3.pool.StatelessObjectFactory;
+
+/**
+ * A pool with a maximum size.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @author <a href="mailto:kabir.khan at jboss.org">Kabir Khan</a>
+ * @version $Revision: $
+ */
+public class StrictMaxPool<T> implements Pool<T>
+{
+   private StatelessObjectFactory<T> factory;
+   private Semaphore semaphore;
+   private int maxSize;
+   private long timeout;
+   private TimeUnit timeUnit;
+   private LinkedList<T> pool = new LinkedList<T>();
+   
+   public StrictMaxPool(StatelessObjectFactory<T> factory, int maxSize, long timeout, TimeUnit timeUnit)
+   {
+      assert factory != null : "factory is null";
+      
+      this.factory = factory;
+      this.maxSize = maxSize;
+      this.semaphore = new Semaphore(maxSize, true);
+      this.timeout = timeout;
+      this.timeUnit = timeUnit;
+   }
+   
+   public void discard(T obj)
+   {
+      throw new RuntimeException("NYI");
+   }
+
+   public T get()
+   {
+      try
+      {
+         boolean acquired = semaphore.tryAcquire(timeout, timeUnit);
+         if(!acquired)
+            throw new RuntimeException("Failed to acquire a permit within " + timeout + " " + timeUnit);
+      }
+      catch (InterruptedException e)
+      {
+         throw new RuntimeException("Acquire semaphore was interupted");
+      }
+      
+      synchronized(pool)
+      {
+         if(!pool.isEmpty())
+         {
+            return pool.removeFirst();
+         }
+      }
+      
+      return factory.create();
+   }
+
+   public void release(T obj)
+   {
+      boolean destroyIt = false;
+      synchronized (pool)
+      {
+         if(pool.size() < maxSize)
+            pool.add(obj);
+         else
+            destroyIt = true;
+      }
+      if(destroyIt)
+         factory.destroy(obj);
+      semaphore.release();
+   }
+
+   public void start()
+   {
+      // TODO Auto-generated method stub
+      
+   }
+
+   public void stop()
+   {
+      for(T obj : pool)
+      {
+         factory.destroy(obj);
+      }
+      pool.clear();
+   }
+
+}


Property changes on: projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/strictmax/StrictMaxPool.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/threadlocal/ThreadLocalPool.java
===================================================================
--- projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/threadlocal/ThreadLocalPool.java	                        (rev 0)
+++ projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/threadlocal/ThreadLocalPool.java	2007-09-25 18:17:06 UTC (rev 65604)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.pool.threadlocal;
+
+import org.jboss.ejb3.pool.Pool;
+import org.jboss.ejb3.pool.StatelessObjectFactory;
+import org.jboss.ejb3.pool.inifinite.InfinitePool;
+
+/**
+ * A pool which keeps an object ready per thread.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: $
+ */
+public class ThreadLocalPool<T> implements Pool<T>
+{
+   private Pool<T> delegate;
+   private WeakThreadLocal<T> pool = new WeakThreadLocal<T>();
+   
+   public ThreadLocalPool(StatelessObjectFactory<T> factory)
+   {
+      delegate = new InfinitePool<T>(factory);
+   }
+   
+   public void discard(T obj)
+   {
+      throw new RuntimeException("NYI");
+   }
+
+   public T get()
+   {
+      if(pool.get() == null)
+      {
+         return delegate.get();
+      }
+      else
+      {
+         T obj = pool.get();
+         pool.set(null);
+         return obj;
+      }
+   }
+
+   public void release(T obj)
+   {
+      if(pool.get() == null)
+      {
+         pool.set(obj);
+      }
+      else
+      {
+         delegate.release(obj);
+      }
+   }
+
+   public void start()
+   {
+      delegate.start();
+   }
+
+   public void stop()
+   {
+      delegate.stop();
+      
+      pool.remove();
+   }
+
+}


Property changes on: projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/threadlocal/ThreadLocalPool.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Copied: projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/threadlocal/WeakThreadLocal.java (from rev 65596, trunk/ejb3/src/main/org/jboss/lang/ref/WeakThreadLocal.java)
===================================================================
--- projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/threadlocal/WeakThreadLocal.java	                        (rev 0)
+++ projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/threadlocal/WeakThreadLocal.java	2007-09-25 18:17:06 UTC (rev 65604)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.pool.threadlocal;
+
+import java.lang.ref.WeakReference;
+
+/**
+ * ThreadLocal has an inherent memory leak: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6254531
+ * 
+ * This class will only keep a weak reference so garbage collections works.
+ * 
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class WeakThreadLocal<T>
+{
+   private ThreadLocal<WeakReference<T>> delegate = new ThreadLocal<WeakReference<T>>();
+
+   public T get()
+   {
+      WeakReference<T> ref = delegate.get();
+      if(ref == null)
+         return null;
+      return ref.get();
+   }
+   
+   public void remove()
+   {
+      delegate.remove();
+   }
+
+   public void set(T value)
+   {
+      delegate.set(new WeakReference<T>(value));
+   }
+}


Property changes on: projects/ejb3/trunk/pool/src/main/java/org/jboss/ejb3/pool/threadlocal/WeakThreadLocal.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/test/pool/common/MockBean.java
===================================================================
--- projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/test/pool/common/MockBean.java	                        (rev 0)
+++ projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/test/pool/common/MockBean.java	2007-09-25 18:17:06 UTC (rev 65604)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.pool.common;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class MockBean
+{
+   static int finalized = 0;
+   static int preDestroys = 0;
+   static int postConstructs = 0;
+   
+   @Override
+   protected void finalize() throws Throwable
+   {
+      super.finalize();
+      
+      finalized++;
+   }
+   
+   public static int getFinalized()
+   {
+      return finalized;
+   }
+   
+   public static int getPreDestroys()
+   {
+      return preDestroys;
+   }
+   
+   public static int getPostConstructs()
+   {
+      return postConstructs;
+   }
+   
+   public void postConstruct()
+   {
+      postConstructs++;
+   }
+   
+   public void preDestroy()
+   {
+      preDestroys++;
+   }
+   
+   public static void reset()
+   {
+      finalized = 0;
+      preDestroys = 0;
+      postConstructs = 0;
+   }
+}


Property changes on: projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/test/pool/common/MockBean.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/test/pool/common/MockFactory.java
===================================================================
--- projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/test/pool/common/MockFactory.java	                        (rev 0)
+++ projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/test/pool/common/MockFactory.java	2007-09-25 18:17:06 UTC (rev 65604)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.pool.common;
+
+import org.jboss.ejb3.pool.StatelessObjectFactory;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class MockFactory implements StatelessObjectFactory<MockBean>
+{
+   public MockBean create()
+   {
+      MockBean bean = new MockBean();
+      bean.postConstruct();
+      return bean;
+   }
+
+   public void destroy(MockBean obj)
+   {
+      obj.preDestroy();
+   }
+
+}


Property changes on: projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/test/pool/common/MockFactory.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/test/pool/infinite/InfinitePoolUnitTestCase.java
===================================================================
--- projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/test/pool/infinite/InfinitePoolUnitTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/test/pool/infinite/InfinitePoolUnitTestCase.java	2007-09-25 18:17:06 UTC (rev 65604)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.pool.infinite;
+
+import org.jboss.ejb3.pool.Pool;
+import org.jboss.ejb3.pool.StatelessObjectFactory;
+import org.jboss.ejb3.pool.inifinite.InfinitePool;
+import org.jboss.ejb3.test.pool.common.MockBean;
+import org.jboss.ejb3.test.pool.common.MockFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class InfinitePoolUnitTestCase extends TestCase
+{
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      
+      MockBean.reset();
+   }
+   
+   public void test1()
+   {
+      StatelessObjectFactory<MockBean> factory = new MockFactory();
+      Pool<MockBean> pool = new InfinitePool<MockBean>(factory);
+      MockBean bean = pool.get();
+      
+      assertEquals(1, MockBean.getPostConstructs());
+      
+      pool.release(bean);
+      
+      assertEquals(1, MockBean.getPreDestroys());
+   }
+
+   public void test100()
+   {
+      StatelessObjectFactory<MockBean> factory = new MockFactory();
+      Pool<MockBean> pool = new InfinitePool<MockBean>(factory);
+      
+      for(int i = 1; i <= 100; i++)
+      {
+         MockBean bean = pool.get();
+         
+         assertEquals(i, MockBean.getPostConstructs());
+         
+         pool.release(bean);
+         
+         assertEquals(i, MockBean.getPreDestroys());
+      }
+   }
+}


Property changes on: projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/test/pool/infinite/InfinitePoolUnitTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/test/pool/strictmax/StrictMaxUnitTestCase.java
===================================================================
--- projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/test/pool/strictmax/StrictMaxUnitTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/test/pool/strictmax/StrictMaxUnitTestCase.java	2007-09-25 18:17:06 UTC (rev 65604)
@@ -0,0 +1,165 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.pool.strictmax;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+import org.jboss.ejb3.pool.Pool;
+import org.jboss.ejb3.pool.StatelessObjectFactory;
+import org.jboss.ejb3.pool.strictmax.StrictMaxPool;
+import org.jboss.ejb3.test.pool.common.MockBean;
+import org.jboss.ejb3.test.pool.common.MockFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class StrictMaxUnitTestCase extends TestCase
+{
+   int used = 0;
+   
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      
+      MockBean.reset();
+      used = 0;
+   }
+   
+   public void test1()
+   {
+      StatelessObjectFactory<MockBean> factory = new MockFactory();
+      Pool<MockBean> pool = new StrictMaxPool<MockBean>(factory, 10, 1, TimeUnit.SECONDS);
+      pool.start();
+      
+      MockBean beans[] = new MockBean[10];
+      for(int i = 0; i < beans.length; i++)
+      {
+         beans[i] = pool.get();
+      }
+      
+      for(int i = 0; i < beans.length; i++)
+      {
+         pool.release(beans[i]);
+         beans[i] = null;
+      }
+      
+      pool.stop();
+      
+      assertEquals(10, MockBean.getPostConstructs());
+      assertEquals(10, MockBean.getPreDestroys());
+   }
+   
+   /**
+    * More threads than the pool size.
+    */
+   public void testMultiThread() throws Exception
+   {
+      StatelessObjectFactory<MockBean> factory = new MockFactory();
+      final Pool<MockBean> pool = new StrictMaxPool<MockBean>(factory, 10, 1, TimeUnit.SECONDS);
+      pool.start();
+      
+      Callable<Void> task = new Callable<Void>()
+      {
+         public Void call() throws Exception
+         {
+            for(int i = 0; i < 20; i++)
+            {
+               MockBean bean = pool.get();
+               
+               Thread.sleep(50);
+               
+               pool.release(bean);
+               
+               bean = null;
+               
+               used++;
+            }
+            
+            return null;
+         }
+      };
+      
+      ExecutorService service = Executors.newFixedThreadPool(20);
+      Future<?> results[] = new Future<?>[20];
+      for(int i = 0; i < results.length; i++)
+      {
+         results[i] = service.submit(task);
+      }
+      
+      for(Future<?> result : results)
+      {
+         result.get(5, TimeUnit.SECONDS);
+      }
+      
+      service.shutdown();
+      
+      pool.stop();
+      
+      assertEquals(400, used);
+      assertEquals(10, MockBean.getPostConstructs());
+      assertEquals(10, MockBean.getPreDestroys());
+   }
+   
+   public void testTooMany()
+   {
+      StatelessObjectFactory<MockBean> factory = new MockFactory();
+      Pool<MockBean> pool = new StrictMaxPool<MockBean>(factory, 10, 1, TimeUnit.SECONDS);
+      pool.start();
+      
+      MockBean beans[] = new MockBean[10];
+      for(int i = 0; i < beans.length; i++)
+      {
+         beans[i] = pool.get();
+      }
+      
+      try
+      {
+         pool.get();
+         fail("should have thrown an exception");
+      }
+      catch(Exception e)
+      {
+         assertEquals("Failed to acquire a permit within 1 SECONDS", e.getMessage());
+      }
+      
+      for(int i = 0; i < beans.length; i++)
+      {
+         pool.release(beans[i]);
+         beans[i] = null;
+      }
+      
+      pool.stop();
+      
+      assertEquals(10, MockBean.getPostConstructs());
+      assertEquals(10, MockBean.getPreDestroys());
+   }
+}


Property changes on: projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/test/pool/strictmax/StrictMaxUnitTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/test/pool/threadlocal/ThreadLocalPoolUnitTestCase.java
===================================================================
--- projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/test/pool/threadlocal/ThreadLocalPoolUnitTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/test/pool/threadlocal/ThreadLocalPoolUnitTestCase.java	2007-09-25 18:17:06 UTC (rev 65604)
@@ -0,0 +1,253 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.pool.threadlocal;
+
+import java.lang.Thread.UncaughtExceptionHandler;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+import org.jboss.ejb3.pool.StatelessObjectFactory;
+import org.jboss.ejb3.pool.threadlocal.ThreadLocalPool;
+import org.jboss.ejb3.test.pool.common.MockBean;
+import org.jboss.ejb3.test.pool.common.MockFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class ThreadLocalPoolUnitTestCase extends TestCase
+{
+   private static class MyUncaughtExceptionHandler implements UncaughtExceptionHandler
+   {
+      private Throwable uncaught;
+      
+      Throwable getUncaughtException()
+      {
+         return uncaught;
+      }
+      
+      public void uncaughtException(Thread t, Throwable e)
+      {
+         this.uncaught = e;
+      }
+   }
+   
+   private static void gc()
+   {
+      for(int i = 0; i < 3; i++)
+      {
+         System.gc();
+         try
+         {
+            Thread.sleep(100);
+         }
+         catch (InterruptedException e)
+         {
+            // ignore
+         }
+         System.runFinalization();
+      }
+   }
+   
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      
+      MockBean.reset();
+   }
+   
+   @Override
+   protected void tearDown() throws Exception
+   {
+      super.tearDown();
+      
+      gc();
+   }
+   
+   /**
+    * The basic assumption is that we only create
+    * one object per thread and keep that one pooled.
+    */
+   public void testBasic()
+   {
+      StatelessObjectFactory<MockBean> factory = new MockFactory();
+      ThreadLocalPool<MockBean> pool = new ThreadLocalPool<MockBean>(factory);
+      pool.start();
+      
+      for(int i = 0; i < 10; i++)
+      {
+         MockBean bean = pool.get();
+         
+         pool.release(bean);
+         
+         bean = null;
+      }
+      
+      assertEquals(1, MockBean.getPostConstructs());
+   }
+   
+   public void testBasicMultiThreaded() throws Exception
+   {
+      StatelessObjectFactory<MockBean> factory = new MockFactory();
+      final ThreadLocalPool<MockBean> pool = new ThreadLocalPool<MockBean>(factory);
+      pool.start();
+      
+      Callable<?> task = new Callable<Void>()
+      {
+         public Void call() throws Exception
+         {
+            for(int i = 0; i < 10; i++)
+            {
+               MockBean bean = pool.get();
+               
+               pool.release(bean);
+               
+               bean = null;
+            }
+            return null;
+         }
+      };
+      
+      ExecutorService service = Executors.newFixedThreadPool(10);
+      Future<?> results[] = new Future<?>[10];
+      for(int i = 0; i < results.length; i++)
+      {
+         results[i] = service.submit(task);
+      }
+      
+      for(Future<?> result : results)
+      {
+         result.get(5, TimeUnit.SECONDS);
+      }
+      
+      service.shutdown();
+      boolean terminated = service.awaitTermination(5, TimeUnit.SECONDS);
+      assertTrue(terminated);
+      
+      assertEquals(10, MockBean.getPostConstructs());
+   }
+   
+   /**
+    * Check testMemLeak first.
+    * 
+    * The problem with WeakThreadLocal is that beans
+    * can be gc'd while in the pool (EJBTHREE-1031).
+    * @see testMemLeak
+    */
+   public void testGCTooSoon() throws Exception
+   {
+      StatelessObjectFactory<MockBean> factory = new MockFactory();
+      ThreadLocalPool<MockBean> pool = new ThreadLocalPool<MockBean>(factory);
+      pool.start();
+      
+      MockBean bean = pool.get();
+      
+      pool.release(bean);
+      
+      bean = null;
+      
+      gc();
+      
+      assertEquals(0, MockBean.getFinalized());
+   }
+   
+   /**
+    * Test the old EJBTHREE-840 mem leak.
+    * @throws Exception 
+    */
+   public void testMemLeak() throws Exception
+   {
+      assertEquals(0, MockBean.getFinalized());
+      
+      StatelessObjectFactory<MockBean> factory = new MockFactory();
+      final ThreadLocalPool<MockBean> pool = new ThreadLocalPool<MockBean>(factory);
+      pool.start();
+      
+      Runnable test = new Runnable()
+      {
+         public void run()
+         {
+            MockBean bean = pool.get();
+            
+            pool.release(bean);
+            
+            bean = null;
+            
+            while(!Thread.currentThread().isInterrupted())
+            {
+               try
+               {
+                  Thread.sleep(1000);
+               }
+               catch (InterruptedException e)
+               {
+                  return;
+               }
+            }
+         }
+      };
+      
+      MyUncaughtExceptionHandler eh = new MyUncaughtExceptionHandler();
+      
+      Thread threads[] = new Thread[10];
+      for(int i = 0; i < threads.length; i++)
+      {
+         threads[i] = new Thread(test);
+         threads[i].setUncaughtExceptionHandler(eh);
+         threads[i].start();
+      }
+      
+      assertNull(eh.getUncaughtException());
+
+      Thread.sleep(500);
+      
+      // We stop the pool (undeploy / redeploy). The threads remain alive, because
+      // they're managed by the remote connection pool.
+      pool.stop();
+      
+      gc();
+      
+      assertNull(eh.getUncaughtException());
+      
+      assertEquals(10, MockBean.getPostConstructs());
+      assertEquals(10, MockBean.getFinalized());
+      // Note: that before the Infinite delegate we didn't call preDestroy
+      assertEquals(10, MockBean.getPreDestroys());
+
+      for(Thread thread : threads)
+      {
+         thread.interrupt();
+         thread.join(5000);
+         assertFalse(thread.isAlive());
+      }
+      
+      assertNull(eh.getUncaughtException());
+   }
+}


Property changes on: projects/ejb3/trunk/pool/src/test/java/org/jboss/ejb3/test/pool/threadlocal/ThreadLocalPoolUnitTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native




More information about the jboss-cvs-commits mailing list