Author: slaurent
Date: Thu May  8 19:36:10 2014
New Revision: 1593392

URL: http://svn.apache.org/r1593392
Log:
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/tc7.0.x/trunk/java/org/apache/tomcat/util/threads/StopPooledThreadException.java
      - copied unchanged from r1593132, 
tomcat/trunk/java/org/apache/tomcat/util/threads/StopPooledThreadException.java
Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/threads/TaskThread.java
    
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/threads/ThreadPoolExecutor.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
  Merged /tomcat/trunk:r1593132

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/threads/TaskThread.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/threads/TaskThread.java?rev=1593392&r1=1593391&r2=1593392&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/threads/TaskThread.java 
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/threads/TaskThread.java 
Thu May  8 19:36:10 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/tc7.0.x/trunk/java/org/apache/tomcat/util/threads/ThreadPoolExecutor.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/threads/ThreadPoolExecutor.java?rev=1593392&r1=1593391&r2=1593392&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/threads/ThreadPoolExecutor.java
 (original)
+++ 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/threads/ThreadPoolExecutor.java
 Thu May  8 19:36:10 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;
 
 /**
@@ -44,8 +41,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
@@ -117,16 +112,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/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1593392&r1=1593391&r2=1593392&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Thu May  8 19:36:10 2014
@@ -164,6 +164,10 @@
         <bug>56472</bug>: Allow NamingContextListener to clean up on stop if 
its
         start failed. (kkolinko)
       </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-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to