geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r179720 - in /geronimo/trunk/modules/core/src: java/org/apache/geronimo/pool/ThreadPool.java test/ test/org/ test/org/apache/ test/org/apache/geronimo/ test/org/apache/geronimo/pool/ test/org/apache/geronimo/pool/ThreadPoolTest.java
Date Fri, 03 Jun 2005 04:23:01 GMT
Author: dain
Date: Thu Jun  2 21:23:00 2005
New Revision: 179720

URL: http://svn.apache.org/viewcvs?rev=179720&view=rev
Log:
Throw an exception if a thread can not be immedately acquired

Added:
    geronimo/trunk/modules/core/src/test/
    geronimo/trunk/modules/core/src/test/org/
    geronimo/trunk/modules/core/src/test/org/apache/
    geronimo/trunk/modules/core/src/test/org/apache/geronimo/
    geronimo/trunk/modules/core/src/test/org/apache/geronimo/pool/
    geronimo/trunk/modules/core/src/test/org/apache/geronimo/pool/ThreadPoolTest.java
Modified:
    geronimo/trunk/modules/core/src/java/org/apache/geronimo/pool/ThreadPool.java

Modified: geronimo/trunk/modules/core/src/java/org/apache/geronimo/pool/ThreadPool.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/core/src/java/org/apache/geronimo/pool/ThreadPool.java?rev=179720&r1=179719&r2=179720&view=diff
==============================================================================
--- geronimo/trunk/modules/core/src/java/org/apache/geronimo/pool/ThreadPool.java (original)
+++ geronimo/trunk/modules/core/src/java/org/apache/geronimo/pool/ThreadPool.java Thu Jun
 2 21:23:00 2005
@@ -18,7 +18,6 @@
 package org.apache.geronimo.pool;
 
 import EDU.oswego.cs.dl.util.concurrent.Executor;
-import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
 import EDU.oswego.cs.dl.util.concurrent.PooledExecutor;
 import EDU.oswego.cs.dl.util.concurrent.ThreadFactory;
 import org.apache.geronimo.gbean.GBeanInfo;
@@ -35,7 +34,8 @@
     private int nextWorkerID = 0;
 
     public ThreadPool(final int poolSize, final String poolName, final long keepAliveTime,
final ClassLoader classLoader) {
-        PooledExecutor p = new PooledExecutor(new LinkedQueue(), poolSize);
+        PooledExecutor p = new PooledExecutor(poolSize);
+        p.abortWhenBlocked();
         p.setKeepAliveTime(keepAliveTime);
         p.setMinimumPoolSize(poolSize);
         p.setThreadFactory(new ThreadFactory() {

Added: geronimo/trunk/modules/core/src/test/org/apache/geronimo/pool/ThreadPoolTest.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/core/src/test/org/apache/geronimo/pool/ThreadPoolTest.java?rev=179720&view=auto
==============================================================================
--- geronimo/trunk/modules/core/src/test/org/apache/geronimo/pool/ThreadPoolTest.java (added)
+++ geronimo/trunk/modules/core/src/test/org/apache/geronimo/pool/ThreadPoolTest.java Thu
Jun  2 21:23:00 2005
@@ -0,0 +1,76 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.pool;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ThreadPoolTest extends TestCase {
+    private final Object lock = new Object();
+    private boolean ready;
+    private ThreadPool threadPool;
+
+    public void testPoolLimit() throws Exception {
+        // grab the only thread in the pool
+        ready = false;
+        threadPool.execute(new Runnable() {
+            public void run() {
+                synchronized(lock) {
+                    ready = true;
+                    lock.notifyAll();
+                    try {
+                        lock.wait();
+                    } catch (InterruptedException e) {
+                    }
+                }
+            }
+        });
+
+        // wait for up to 5 seconds for the thread above to start running
+        synchronized(lock) {
+            if (!ready) {
+                lock.wait(5000);
+            }
+        }
+        assertTrue(ready);
+
+        // try to schedule another task
+        try {
+            threadPool.execute(new Runnable(){
+                public void run() {
+                }
+            });
+            fail("Should not have been able to schedule second task");
+        } catch (RuntimeException e) {
+            // expected
+        }
+    }
+
+    public void setUp() throws Exception {
+        threadPool = new ThreadPool(1, "foo", Long.MAX_VALUE, ThreadPoolTest.class.getClassLoader());
+        threadPool.doStart();
+    }
+
+    public void tearDown() throws Exception {
+        threadPool.doStop();
+        synchronized(lock) {
+            lock.notifyAll();
+        }
+    }
+}



Mime
View raw message