Merge "Fix checkListKey not checking actual/expected values"
[yangtools.git] / common / util / src / main / java / org / opendaylight / yangtools / util / concurrent / FastThreadPoolExecutor.java
index b7549eb24e7fc602293bce054ba5ed069ecc6c1f..60a1b674609f6ef8268439e952f3fbdb260b432b 100644 (file)
@@ -8,19 +8,18 @@
 
 package org.opendaylight.yangtools.util.concurrent;
 
-import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 
-import com.google.common.base.Objects;
-import com.google.common.base.Objects.ToStringHelper;
+import com.google.common.base.MoreObjects;
+import com.google.common.base.MoreObjects.ToStringHelper;
 import com.google.common.util.concurrent.ThreadFactoryBuilder;
 
 /**
  * A ThreadPoolExecutor with a specified bounded queue capacity that favors creating new threads
  * over queuing, as the former is faster.
  * <p>
- * See {@link SpecialExecutors#newFastBlockingThreadPool} for more details.
+ * See {@link SpecialExecutors#newBoundedFastThreadPool} for more details.
  *
  * @author Thomas Pantelis
  */
@@ -70,7 +69,7 @@ public class FastThreadPoolExecutor extends ThreadPoolExecutor {
         // reached, subsequent tasks will be queued. If the queue is full, tasks will be rejected.
 
         super( maximumPoolSize, maximumPoolSize, keepAliveTime, unit,
-               new LinkedBlockingQueue<Runnable>( maximumQueueSize ) );
+               new TrackingLinkedBlockingQueue<Runnable>( maximumQueueSize ) );
 
         this.threadPrefix = threadPrefix;
         this.maximumQueueSize = maximumQueueSize;
@@ -82,6 +81,12 @@ public class FastThreadPoolExecutor extends ThreadPoolExecutor {
             // Need to specifically configure core threads to timeout.
             allowCoreThreadTimeOut( true );
         }
+
+        setRejectedExecutionHandler( CountingRejectedExecutionHandler.newAbortPolicy() );
+    }
+
+    public long getLargestQueueSize() {
+        return ((TrackingLinkedBlockingQueue<?>)getQueue()).getLargestQueueSize();
     }
 
     protected ToStringHelper addToStringAttributes( ToStringHelper toStringHelper ) {
@@ -90,12 +95,13 @@ public class FastThreadPoolExecutor extends ThreadPoolExecutor {
 
     @Override
     public final String toString() {
-        return addToStringAttributes( Objects.toStringHelper( this )
+        return addToStringAttributes( MoreObjects.toStringHelper( this )
                 .add( "Thread Prefix", threadPrefix )
                 .add( "Current Thread Pool Size", getPoolSize() )
                 .add( "Largest Thread Pool Size", getLargestPoolSize() )
                 .add( "Max Thread Pool Size", getMaximumPoolSize() )
                 .add( "Current Queue Size", getQueue().size() )
+                .add( "Largest Queue Size", getLargestQueueSize() )
                 .add( "Max Queue Size", maximumQueueSize )
                 .add( "Active Thread Count", getActiveCount() )
                 .add( "Completed Task Count", getCompletedTaskCount() )