X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=common%2Futil%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Futil%2Fconcurrent%2FCountingRejectedExecutionHandler.java;h=8fd45dc310ac0bafc80fce37a3b1f675f8bba182;hb=1eb87c819cc6881ca7be74917a5d0bb7a9cad41f;hp=c44864350e863dc639e307d23fc343efbc38bfc1;hpb=68f459e972f360597301b929b5943082ba9e9730;p=yangtools.git diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/CountingRejectedExecutionHandler.java b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/CountingRejectedExecutionHandler.java index c44864350e..8fd45dc310 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/CountingRejectedExecutionHandler.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/CountingRejectedExecutionHandler.java @@ -9,11 +9,9 @@ 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.AtomicLongFieldUpdater; - +import java.util.concurrent.atomic.LongAdder; import org.opendaylight.yangtools.util.ExecutorServiceUtil; /** @@ -23,10 +21,8 @@ import org.opendaylight.yangtools.util.ExecutorServiceUtil; * @author Thomas Pantelis */ public class CountingRejectedExecutionHandler implements RejectedExecutionHandler { - private static final AtomicLongFieldUpdater COUNTER_UPDATER = - AtomicLongFieldUpdater.newUpdater(CountingRejectedExecutionHandler.class, "rejectedTaskCounter"); + private final LongAdder rejectedTaskCounter = new LongAdder(); private final RejectedExecutionHandler delegate; - private volatile long rejectedTaskCounter; /** * Constructor. @@ -39,15 +35,15 @@ public class CountingRejectedExecutionHandler implements RejectedExecutionHandle @Override public void rejectedExecution( final Runnable task, final ThreadPoolExecutor executor ) { - COUNTER_UPDATER.incrementAndGet(this); - delegate.rejectedExecution( task, executor ); + rejectedTaskCounter.increment(); + delegate.rejectedExecution(task, executor); } /** * Returns the rejected task count. */ public long getRejectedTaskCount() { - return rejectedTaskCounter; + return rejectedTaskCounter.sum(); } /** @@ -56,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()); } /** @@ -71,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()); } }