Author: markt Date: Mon Sep 14 09:46:34 2015 New Revision: 1702886 URL: http://svn.apache.org/r1702886 Log: Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=58370 Fix data races when executor is being shut down
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AbstractEndpoint.java Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AbstractEndpoint.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/AbstractEndpoint.java?rev=1702886&r1=1702885&r2=1702886&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/AbstractEndpoint.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/AbstractEndpoint.java Mon Sep 14 09:46:34 2015 @@ -379,7 +379,7 @@ public abstract class AbstractEndpoint<S private Executor executor = null; public void setExecutor(Executor executor) { this.executor = executor; - this.internalExecutor = (executor==null); + this.internalExecutor = (executor == null); } public Executor getExecutor() { return executor; } @@ -481,11 +481,12 @@ public abstract class AbstractEndpoint<S } public void setMinSpareThreads(int minSpareThreads) { this.minSpareThreads = minSpareThreads; - if (running && executor!=null) { + Executor executor = this.executor; + if (running && executor != null) { if (executor instanceof java.util.concurrent.ThreadPoolExecutor) { - ((java.util.concurrent.ThreadPoolExecutor)executor).setCorePoolSize(minSpareThreads); + ((java.util.concurrent.ThreadPoolExecutor) executor).setCorePoolSize(minSpareThreads); } else if (executor instanceof ResizableExecutor) { - ((ResizableExecutor)executor).resizePool(minSpareThreads, maxThreads); + ((ResizableExecutor) executor).resizePool(minSpareThreads, maxThreads); } } } @@ -496,11 +497,12 @@ public abstract class AbstractEndpoint<S private int maxThreads = 200; public void setMaxThreads(int maxThreads) { this.maxThreads = maxThreads; - if (running && executor!=null) { + Executor executor = this.executor; + if (running && executor != null) { if (executor instanceof java.util.concurrent.ThreadPoolExecutor) { - ((java.util.concurrent.ThreadPoolExecutor)executor).setMaximumPoolSize(maxThreads); + ((java.util.concurrent.ThreadPoolExecutor) executor).setMaximumPoolSize(maxThreads); } else if (executor instanceof ResizableExecutor) { - ((ResizableExecutor)executor).resizePool(minSpareThreads, maxThreads); + ((ResizableExecutor) executor).resizePool(minSpareThreads, maxThreads); } } } @@ -508,6 +510,7 @@ public abstract class AbstractEndpoint<S return getMaxThreadsExecutor(running); } protected int getMaxThreadsExecutor(boolean useExecutor) { + Executor executor = this.executor; if (useExecutor && executor != null) { if (executor instanceof java.util.concurrent.ThreadPoolExecutor) { return ((java.util.concurrent.ThreadPoolExecutor)executor).getMaximumPoolSize(); @@ -644,11 +647,12 @@ public abstract class AbstractEndpoint<S * @return the amount of threads that are managed by the pool */ public int getCurrentThreadCount() { - if (executor!=null) { + Executor executor = this.executor; + if (executor != null) { if (executor instanceof ThreadPoolExecutor) { - return ((ThreadPoolExecutor)executor).getPoolSize(); + return ((ThreadPoolExecutor) executor).getPoolSize(); } else if (executor instanceof ResizableExecutor) { - return ((ResizableExecutor)executor).getPoolSize(); + return ((ResizableExecutor) executor).getPoolSize(); } else { return -1; } @@ -663,11 +667,12 @@ public abstract class AbstractEndpoint<S * @return the amount of threads that are in use */ public int getCurrentThreadsBusy() { - if (executor!=null) { + Executor executor = this.executor; + if (executor != null) { if (executor instanceof ThreadPoolExecutor) { - return ((ThreadPoolExecutor)executor).getActiveCount(); + return ((ThreadPoolExecutor) executor).getActiveCount(); } else if (executor instanceof ResizableExecutor) { - return ((ResizableExecutor)executor).getActiveCount(); + return ((ResizableExecutor) executor).getActiveCount(); } else { return -1; } @@ -694,8 +699,10 @@ public abstract class AbstractEndpoint<S } public void shutdownExecutor() { - if ( executor!=null && internalExecutor ) { - if ( executor instanceof ThreadPoolExecutor ) { + Executor executor = this.executor; + this.executor = null; + if (executor != null && internalExecutor) { + if (executor instanceof ThreadPoolExecutor) { //this is our internal one, so we need to shut it down ThreadPoolExecutor tpe = (ThreadPoolExecutor) executor; tpe.shutdownNow(); @@ -713,7 +720,6 @@ public abstract class AbstractEndpoint<S TaskQueue queue = (TaskQueue) tpe.getQueue(); queue.setParent(null); } - executor = null; } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org