Author: kkolinko
Date: Fri Jun 8 15:39:09 2012
New Revision: 1348120
URL: http://svn.apache.org/viewvc?rev=1348120&view=rev
Log:
Merged revision 1346519 from tomcat/trunk:
Review of r1298986 (r1298983)
Update comments
Update for one field name variant used by Apache Harmony.
Do not test Method and Field handles for null, as NoSuch(Method|Field)Exception
is thrown instead of null value
This aligns Tomcat 7 with patch proposed for Tomcat 6.
Modified:
tomcat/tc7.0.x/trunk/ (props changed)
tomcat/tc7.0.x/trunk/java/org/apache/catalina/loader/WebappClassLoader.java
Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
Merged /tomcat/trunk:r1346519
Modified:
tomcat/tc7.0.x/trunk/java/org/apache/catalina/loader/WebappClassLoader.java
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/loader/WebappClassLoader.java?rev=1348120&r1=1348119&r2=1348120&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/loader/WebappClassLoader.java
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/loader/WebappClassLoader.java
Fri Jun 8 15:39:09 2012
@@ -2254,6 +2254,8 @@ public class WebappClassLoader
}
// TimerThread can be stopped safely so treat separately
+ // "java.util.TimerThread" in Sun/Oracle JDK
+ // "java.util.Timer$TimerImpl" in Apache Harmony and in
IBM JDK
if
(thread.getClass().getName().startsWith("java.util.Timer") &&
clearReferencesStopTimerThreads) {
clearReferencesStopTimerThread(thread);
@@ -2278,27 +2280,36 @@ public class WebappClassLoader
// shutting down the executor
try {
- Field targetField = null;
- try {
- targetField =
thread.getClass().getDeclaredField("target");
- }catch (NoSuchFieldException nfe){
- targetField =
thread.getClass().getDeclaredField("runnable");
+ // Runnable wrapped by Thread
+ // "target" in Sun/Oracle JDK
+ // "runnable" in IBM JDK
+ // "action" in Apache Harmony
+ Object target = null;
+ for (String fieldName : new String[] { "target",
+ "runnable", "action" }) {
+ try {
+ Field targetField = thread.getClass()
+ .getDeclaredField(fieldName);
+ targetField.setAccessible(true);
+ target = targetField.get(thread);
+ break;
+ } catch (NoSuchFieldException nfe) {
+ continue;
+ }
}
- if (null != targetField){
- targetField.setAccessible(true);
- Object target = targetField.get(thread);
-
- if (target != null &&
- target.getClass().getCanonicalName() !=
null
- &&
target.getClass().getCanonicalName().equals(
-
"java.util.concurrent.ThreadPoolExecutor.Worker")) {
- Field executorField =
-
target.getClass().getDeclaredField("this$0");
- executorField.setAccessible(true);
- Object executor = executorField.get(target);
- if (executor instanceof ThreadPoolExecutor) {
- ((ThreadPoolExecutor)
executor).shutdownNow();
- }
+
+ // "java.util.concurrent" code is in public domain,
+ // so all implementations are similar
+ if (target != null &&
+ target.getClass().getCanonicalName() != null
+ && target.getClass().getCanonicalName().equals(
+
"java.util.concurrent.ThreadPoolExecutor.Worker")) {
+ Field executorField =
+ target.getClass().getDeclaredField("this$0");
+ executorField.setAccessible(true);
+ Object executor = executorField.get(target);
+ if (executor instanceof ThreadPoolExecutor) {
+ ((ThreadPoolExecutor) executor).shutdownNow();
}
}
} catch (SecurityException e) {
@@ -2362,9 +2373,12 @@ public class WebappClassLoader
private void clearReferencesStopTimerThread(Thread thread) {
// Need to get references to:
- // - newTasksMayBeScheduled field
+ // in Sun/Oracle JDK:
+ // - newTasksMayBeScheduled field (in java.util.TimerThread)
// - queue field
// - queue.clear()
+ // in IBM JDK, Apache Harmony:
+ // - cancel() method (in java.util.Timer$TimerImpl)
try {
@@ -2388,11 +2402,9 @@ public class WebappClassLoader
}catch (NoSuchFieldException nfe){
Method cancelMethod =
thread.getClass().getDeclaredMethod("cancel");
- if (null != cancelMethod){
- synchronized(thread) {
- cancelMethod.setAccessible(true);
- cancelMethod.invoke(thread);
- }
+ synchronized(thread) {
+ cancelMethod.setAccessible(true);
+ cancelMethod.invoke(thread);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]