[jboss-svn-commits] JBoss Common SVN: r4931 - in common-core/trunk/src: test/java/org/jboss/test/util/test/concurrent and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Aug 13 11:28:47 EDT 2012


Author: baranowb
Date: 2012-08-13 11:28:47 -0400 (Mon, 13 Aug 2012)
New Revision: 4931

Added:
   common-core/trunk/src/test/java/org/jboss/test/util/test/concurrent/ThreadPoolConcurrencyTestCase.java
Modified:
   common-core/trunk/src/main/java/org/jboss/util/threadpool/BasicThreadPool.java
Log:
JBCOMMON-129

Modified: common-core/trunk/src/main/java/org/jboss/util/threadpool/BasicThreadPool.java
===================================================================
--- common-core/trunk/src/main/java/org/jboss/util/threadpool/BasicThreadPool.java	2012-08-10 12:27:05 UTC (rev 4930)
+++ common-core/trunk/src/main/java/org/jboss/util/threadpool/BasicThreadPool.java	2012-08-13 15:28:47 UTC (rev 4931)
@@ -28,6 +28,7 @@
 import java.util.PriorityQueue;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.PriorityBlockingQueue;
 import java.util.concurrent.RejectedExecutionHandler;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.ThreadPoolExecutor;
@@ -96,7 +97,7 @@
    /** Has the pool been stopped? */
    private AtomicBoolean stopped = new AtomicBoolean(false);
    /** The Heap<TimeoutInfo> of tasks ordered by their completion timeout */
-   private PriorityQueue<TimeoutInfo> tasksWithTimeouts = new PriorityQueue<TimeoutInfo>(13);
+   private PriorityBlockingQueue<TimeoutInfo> tasksWithTimeouts = new PriorityBlockingQueue<TimeoutInfo>(13);
    /** The task completion timeout monitor runnable */
    private TimeoutMonitor timeoutTask;
    /** The trace level logging flag */
@@ -512,12 +513,7 @@
    }
    protected TimeoutInfo getNextTimeout()
    {
-      TimeoutInfo info = null;
-      if(this.tasksWithTimeouts.isEmpty() == false)
-      {
-         info = this.tasksWithTimeouts.remove();
-      }
-      return info;
+      return this.tasksWithTimeouts.poll();
    }
    
    protected void setDefaultThreadContextClassLoader(Thread thread)

Added: common-core/trunk/src/test/java/org/jboss/test/util/test/concurrent/ThreadPoolConcurrencyTestCase.java
===================================================================
--- common-core/trunk/src/test/java/org/jboss/test/util/test/concurrent/ThreadPoolConcurrencyTestCase.java	                        (rev 0)
+++ common-core/trunk/src/test/java/org/jboss/test/util/test/concurrent/ThreadPoolConcurrencyTestCase.java	2012-08-13 15:28:47 UTC (rev 4931)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., 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.test.util.test.concurrent;
+
+import junit.framework.TestCase;
+
+import org.jboss.util.threadpool.BasicThreadPool;
+import org.jboss.util.threadpool.BlockingMode;
+
+/**
+ * @author baranowb
+ *
+ */
+public class ThreadPoolConcurrencyTestCase extends TestCase{
+
+    public void testConcurrency() throws Exception{
+        BasicThreadPool pool = new BasicThreadPool();
+        pool.setBlockingMode(BlockingMode.RUN);
+        pool.setMaximumQueueSize(20);
+        pool.setMaximumPoolSize(1);
+        final long startTime = System.currentTimeMillis();
+        final long destTime = startTime + 1000*30;
+        for(;;){
+            pool.run(new Runnable() {
+
+             public void run() {
+                
+                 
+             }
+         }, 0, 1000);
+            if(System.currentTimeMillis()>destTime){
+                break;
+            }
+        }  
+    }
+}



More information about the jboss-svn-commits mailing list