Address trivial eclipse warnings
[yangtools.git] / common / util / src / main / java / org / opendaylight / yangtools / util / concurrent / CountingRejectedExecutionHandler.java
index ab010c964de2a7ec32a12c7ef40458068ede6c5e..8fd45dc310ac0bafc80fce37a3b1f675f8bba182 100644 (file)
@@ -8,14 +8,12 @@
 
 package org.opendaylight.yangtools.util.concurrent;
 
+import com.google.common.base.Preconditions;
 import java.util.concurrent.RejectedExecutionHandler;
 import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.atomic.AtomicLong;
-
+import java.util.concurrent.atomic.LongAdder;
 import org.opendaylight.yangtools.util.ExecutorServiceUtil;
 
-import com.google.common.base.Preconditions;
-
 /**
  * A RejectedExecutionHandler that delegates to a backing RejectedExecutionHandler and counts the
  * number of rejected tasks.
@@ -23,30 +21,29 @@ import com.google.common.base.Preconditions;
  * @author Thomas Pantelis
  */
 public class CountingRejectedExecutionHandler implements RejectedExecutionHandler {
-
+    private final LongAdder rejectedTaskCounter = new LongAdder();
     private final RejectedExecutionHandler delegate;
-    private final AtomicLong rejectedTaskCounter = new AtomicLong();
 
     /**
      * Constructor.
      *
      * @param delegate the backing RejectedExecutionHandler.
      */
-    public CountingRejectedExecutionHandler( RejectedExecutionHandler delegate ) {
+    public CountingRejectedExecutionHandler( final RejectedExecutionHandler delegate ) {
         this.delegate = Preconditions.checkNotNull( delegate );
     }
 
     @Override
-    public void rejectedExecution( Runnable task, ThreadPoolExecutor executor ) {
-        rejectedTaskCounter.incrementAndGet();
-        delegate.rejectedExecution( task, executor );
+    public void rejectedExecution( final Runnable task, final ThreadPoolExecutor executor ) {
+        rejectedTaskCounter.increment();
+        delegate.rejectedExecution(task, executor);
     }
 
     /**
      * Returns the rejected task count.
      */
-    public long getRejectedTaskCount(){
-        return rejectedTaskCounter.get();
+    public long getRejectedTaskCount() {
+        return rejectedTaskCounter.sum();
     }
 
     /**
@@ -55,14 +52,14 @@ public class CountingRejectedExecutionHandler implements RejectedExecutionHandle
      * the task is discarded.
      */
     public static CountingRejectedExecutionHandler newCallerRunsPolicy() {
-        return new CountingRejectedExecutionHandler( new ThreadPoolExecutor.CallerRunsPolicy() );
+        return new CountingRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
     }
 
     /**
      * Returns a counting handler for rejected tasks that throws a RejectedExecutionException.
      */
     public static CountingRejectedExecutionHandler newAbortPolicy() {
-        return new CountingRejectedExecutionHandler( new ThreadPoolExecutor.AbortPolicy() );
+        return new CountingRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
     }
 
     /**
@@ -70,6 +67,6 @@ public class CountingRejectedExecutionHandler implements RejectedExecutionHandle
      * {@link ThreadPoolExecutor}'s backing queue until it can add the task to the queue.
      */
     public static CountingRejectedExecutionHandler newCallerWaitsPolicy() {
-        return new CountingRejectedExecutionHandler( ExecutorServiceUtil.waitInQueueExecutionHandler() );
+        return new CountingRejectedExecutionHandler(ExecutorServiceUtil.waitInQueueExecutionHandler());
     }
 }