This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 7.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 4160df2b15a9af62cf9bb91069a1adb7613cf4db Author: Mark Thomas <ma...@apache.org> AuthorDate: Thu Nov 14 21:59:04 2019 +0000 Back-port SpotBugs fixes and/or clean-up --- .../apache/tomcat/util/net/NioBlockingSelector.java | 4 ++-- java/org/apache/tomcat/util/threads/TaskQueue.java | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/java/org/apache/tomcat/util/net/NioBlockingSelector.java b/java/org/apache/tomcat/util/net/NioBlockingSelector.java index 1c467e8..080e4cc 100644 --- a/java/org/apache/tomcat/util/net/NioBlockingSelector.java +++ b/java/org/apache/tomcat/util/net/NioBlockingSelector.java @@ -41,7 +41,7 @@ public class NioBlockingSelector { private static final Log log = LogFactory.getLog(NioBlockingSelector.class); - private static int threadCounter = 0; + private static AtomicInteger threadCounter = new AtomicInteger(0); private Queue<KeyReference> keyReferenceQueue = new ConcurrentLinkedQueue<KeyReference>(); @@ -58,7 +58,7 @@ public class NioBlockingSelector { poller = new BlockPoller(); poller.selector = sharedSelector; poller.setDaemon(true); - poller.setName("NioBlockingSelector.BlockPoller-"+(++threadCounter)); + poller.setName("NioBlockingSelector.BlockPoller-"+(threadCounter.getAndIncrement())); poller.start(); } diff --git a/java/org/apache/tomcat/util/threads/TaskQueue.java b/java/org/apache/tomcat/util/threads/TaskQueue.java index 0221295..600fe5b 100644 --- a/java/org/apache/tomcat/util/threads/TaskQueue.java +++ b/java/org/apache/tomcat/util/threads/TaskQueue.java @@ -22,21 +22,20 @@ import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.TimeUnit; /** - * As task queue specifically designed to run with a thread pool executor. - * The task queue is optimised to properly utilize threads within - * a thread pool executor. If you use a normal queue, the executor will spawn threads - * when there are idle threads and you wont be able to force items unto the queue itself - * @author fhanik - * + * As task queue specifically designed to run with a thread pool executor. The + * task queue is optimised to properly utilize threads within a thread pool + * executor. If you use a normal queue, the executor will spawn threads when + * there are idle threads and you wont be able to force items onto the queue + * itself. */ public class TaskQueue extends LinkedBlockingQueue<Runnable> { private static final long serialVersionUID = 1L; - private ThreadPoolExecutor parent = null; + private transient volatile ThreadPoolExecutor parent = null; - // no need to be volatile, the one times when we change and read it occur in - // a single thread (the one that did stop a context and fired listeners) + // No need to be volatile. This is written and read in a single thread + // (when stopping a context and firing the listeners) private Integer forcedRemainingCapacity = null; public TaskQueue() { @@ -56,12 +55,12 @@ public class TaskQueue extends LinkedBlockingQueue<Runnable> { } public boolean force(Runnable o) { - if ( parent.isShutdown() ) throw new RejectedExecutionException("Executor not running, can't force a command into the queue"); + if (parent == null || parent.isShutdown()) throw new RejectedExecutionException("Executor not running, can't force a command into the queue"); return super.offer(o); //forces the item onto the queue, to be used if the task is rejected } public boolean force(Runnable o, long timeout, TimeUnit unit) throws InterruptedException { - if ( parent.isShutdown() ) throw new RejectedExecutionException("Executor not running, can't force a command into the queue"); + if (parent == null || parent.isShutdown()) throw new RejectedExecutionException("Executor not running, can't force a command into the queue"); return super.offer(o,timeout,unit); //forces the item onto the queue, to be used if the task is rejected } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org