From: markt Date: Thu, 30 Sep 2010 17:56:42 +0000 (+0000) Subject: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=49730 X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=7de61860120299ea8ce29544e100d9d912f90562;p=tomcat7.0 Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=49730 Race condition in executor can lead to long delays in request processing git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1003183 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/tomcat/util/threads/TaskQueue.java b/java/org/apache/tomcat/util/threads/TaskQueue.java index 757acc0a6..6471dbcce 100644 --- a/java/org/apache/tomcat/util/threads/TaskQueue.java +++ b/java/org/apache/tomcat/util/threads/TaskQueue.java @@ -19,8 +19,8 @@ package org.apache.tomcat.util.threads; import java.util.Collection; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.RejectedExecutionException; -import java.util.concurrent.ThreadPoolExecutor; 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 @@ -65,7 +65,7 @@ public class TaskQueue extends LinkedBlockingQueue { //we are maxed out on threads, simply queue the object if (parent.getPoolSize() == parent.getMaximumPoolSize()) return super.offer(o); //we have idle threads, just add it to the queue - if (parent.getActiveCount()<(parent.getPoolSize())) return super.offer(o); + if (parent.getSubmittedCount()<(parent.getPoolSize())) return super.offer(o); //if we have less threads than maximum force creation of a new thread if (parent.getPoolSize() workQueue, RejectedExecutionHandler handler) { super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, handler); @@ -53,17 +59,11 @@ public class ThreadPoolExecutor extends java.util.concurrent.ThreadPoolExecutor @Override protected void afterExecute(Runnable r, Throwable t) { - activeCount.decrementAndGet(); - } - - @Override - protected void beforeExecute(Thread t, Runnable r) { - activeCount.incrementAndGet(); + submittedCount.decrementAndGet(); } - @Override - public int getActiveCount() { - return activeCount.get(); + public int getSubmittedCount() { + return submittedCount.get(); } /** @@ -88,6 +88,7 @@ public class ThreadPoolExecutor extends java.util.concurrent.ThreadPoolExecutor * @throws NullPointerException if command or unit is null */ public void execute(Runnable command, long timeout, TimeUnit unit) { + submittedCount.incrementAndGet(); try { super.execute(command); } catch (RejectedExecutionException rx) { @@ -95,13 +96,16 @@ public class ThreadPoolExecutor extends java.util.concurrent.ThreadPoolExecutor final TaskQueue queue = (TaskQueue)super.getQueue(); try { if (!queue.force(command, timeout, unit)) { + submittedCount.decrementAndGet(); throw new RejectedExecutionException("Queue capacity is full."); } } catch (InterruptedException x) { + submittedCount.decrementAndGet(); Thread.interrupted(); throw new RejectedExecutionException(x); } } else { + submittedCount.decrementAndGet(); throw rx; } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 0616d9f50..0b6b8855e 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -87,6 +87,11 @@ managing the PID file and Tomcat does not have write access. (markt) + 49730: Fix a race condition in StandardThreadExector that can + cause requests to experience large delays. Patch provided by Sylvain + Laurent. (markt) + + 49749: Single sign on cookies should have httpOnly flag set using same rules as session cookies. (markt)