You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by sl...@apache.org on 2014/05/07 22:39:07 UTC
svn commit: r1593132 - in /tomcat/trunk:
java/org/apache/tomcat/util/threads/StopPooledThreadException.java
java/org/apache/tomcat/util/threads/TaskThread.java
java/org/apache/tomcat/util/threads/ThreadPoolExecutor.java
webapps/docs/changelog.xml
Author: slaurent
Date: Wed May 7 20:39:07 2014
New Revision: 1593132
URL: http://svn.apache.org/r1593132
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=56492
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=56492
Avoid eclipse debugger pausing on uncaught exceptions when tomcat renews its threads
Added:
tomcat/trunk/java/org/apache/tomcat/util/threads/StopPooledThreadException.java
Modified:
tomcat/trunk/java/org/apache/tomcat/util/threads/TaskThread.java
tomcat/trunk/java/org/apache/tomcat/util/threads/ThreadPoolExecutor.java
tomcat/trunk/webapps/docs/changelog.xml
Added: tomcat/trunk/java/org/apache/tomcat/util/threads/StopPooledThreadException.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/threads/StopPooledThreadException.java?rev=1593132&view=auto
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/threads/StopPooledThreadException.java (added)
+++ tomcat/trunk/java/org/apache/tomcat/util/threads/StopPooledThreadException.java Wed May 7 20:39:07 2014
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tomcat.util.threads;
+
+
+/**
+ * A custom {@link RuntimeException} thrown by the {@link ThreadPoolExecutor}
+ * to signal that the thread should be disposed of.
+ */
+public class StopPooledThreadException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ public StopPooledThreadException(String msg) {
+ super(msg);
+ }
+}
Modified: tomcat/trunk/java/org/apache/tomcat/util/threads/TaskThread.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/threads/TaskThread.java?rev=1593132&r1=1593131&r2=1593132&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/threads/TaskThread.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/threads/TaskThread.java Wed May 7 20:39:07 2014
@@ -16,22 +16,26 @@
*/
package org.apache.tomcat.util.threads;
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+
/**
* A Thread implementation that records the time at which it was created.
*
*/
public class TaskThread extends Thread {
+ private static final Log log = LogFactory.getLog(TaskThread.class);
private final long creationTime;
public TaskThread(ThreadGroup group, Runnable target, String name) {
- super(group, target, name);
+ super(group, new WrappingRunnable(target), name);
this.creationTime = System.currentTimeMillis();
}
public TaskThread(ThreadGroup group, Runnable target, String name,
long stackSize) {
- super(group, target, name, stackSize);
+ super(group, new WrappingRunnable(target), name, stackSize);
this.creationTime = System.currentTimeMillis();
}
@@ -42,4 +46,26 @@ public class TaskThread extends Thread {
return creationTime;
}
+ /**
+ * Wraps a {@link Runnable} to swallow any {@link StopPooledThreadException}
+ * instead of letting it go and potentially trigger a break in a debugger.
+ */
+ private static class WrappingRunnable implements Runnable {
+ private Runnable wrappedRunnable;
+ WrappingRunnable(Runnable wrappedRunnable) {
+ this.wrappedRunnable = wrappedRunnable;
+ }
+ @Override
+ public void run() {
+ try {
+ wrappedRunnable.run();
+ } catch(StopPooledThreadException exc) {
+ //expected : we just swallow the exception to avoid disturbing
+ //debuggers like eclipse's
+ log.debug("Thread exiting on purpose", exc);
+ }
+ }
+
+ }
+
}
Modified: tomcat/trunk/java/org/apache/tomcat/util/threads/ThreadPoolExecutor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/threads/ThreadPoolExecutor.java?rev=1593132&r1=1593131&r2=1593132&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/threads/ThreadPoolExecutor.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/threads/ThreadPoolExecutor.java Wed May 7 20:39:07 2014
@@ -16,7 +16,6 @@
*/
package org.apache.tomcat.util.threads;
-import java.lang.Thread.UncaughtExceptionHandler;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.RejectedExecutionHandler;
@@ -25,8 +24,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
-import org.apache.juli.logging.Log;
-import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.util.res.StringManager;
/**
@@ -43,8 +40,6 @@ public class ThreadPoolExecutor extends
protected static final StringManager sm = StringManager
.getManager("org.apache.tomcat.util.threads.res");
- private static final Log log = LogFactory.getLog(ThreadPoolExecutor.class);
-
/**
* The number of tasks submitted but not yet finished. This includes tasks
* in the queue and tasks that have been handed to a worker thread but the
@@ -116,16 +111,7 @@ public class ThreadPoolExecutor extends
"threadPoolExecutor.threadStoppedToAvoidPotentialLeak",
Thread.currentThread().getName());
- Thread.currentThread().setUncaughtExceptionHandler(
- new UncaughtExceptionHandler() {
- @Override
- public void uncaughtException(Thread t,
- Throwable e) {
- // yes, swallow the exception
- log.debug(msg);
- }
- });
- throw new RuntimeException(msg);
+ throw new StopPooledThreadException(msg);
}
}
}
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1593132&r1=1593131&r2=1593132&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Wed May 7 20:39:07 2014
@@ -150,6 +150,10 @@
<bug>56481</bug>: Work around case insensitivity issue in
<code>URLClassLoader</code> exposed by some recent refactoring. (markt)
</fix>
+ <add>
+ <bug>56492</bug>: Avoid eclipse debugger pausing on uncaught exceptions
+ when tomcat renews its threads. (slaurent)
+ </add>
</changelog>
</subsection>
<subsection name="Coyote">
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org