Author: markt
Date: Tue Nov 5 00:03:04 2013
New Revision: 1538829
URL: http://svn.apache.org/r1538829
Log:
Re-write JAR modification tracking
Modified:
tomcat/trunk/java/org/apache/catalina/loader/LocalStrings.properties
tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java
Modified: tomcat/trunk/java/org/apache/catalina/loader/LocalStrings.properties
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/loader/LocalStrings.properties?rev=1538829&r1=1538828&r2=1538829&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/loader/LocalStrings.properties
(original)
+++ tomcat/trunk/java/org/apache/catalina/loader/LocalStrings.properties Tue
Nov 5 00:03:04 2013
@@ -32,6 +32,9 @@ webappClassLoader.checkThreadLocalsForLe
webappClassLoader.checkThreadsHttpClient=Found HttpClient keep-alive thread
using web application class loader. Fixed by switching thread to the parent
class loader.
webappClassLoader.getThreadGroupError=Unable to obtain the parent for
ThreadGroup [{0}]. It will not be possible to check all threads for potential
memory leaks
webappClassLoader.loadedByThisOrChildFail=Failed to fully check the entries in
an instance of [{0}] for potential memory leaks in context [{1}]
+webappClassLoader.jarsAdded=One of more JARs have been added to the web
application [{0}]
+webappClassLoader.jarsModified=One of more JARs have been modified in the web
application [{0}]
+webappClassLoader.jarsRemoved=One of more JARs have been removed from the web
application [{0}]
webappClassLoader.stopThreadFail=Failed to terminate thread named [{0}] for
web application [{1}]
webappClassLoader.stopTimerThreadFail=Failed to terminate TimerThread named
[{0}] for web application [{1}]
webappClassLoader.validationErrorJarPath=Unable to validate JAR entry with
name {0}
Modified: tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java?rev=1538829&r1=1538828&r2=1538829&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java
(original)
+++ tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java Tue Nov
5 00:03:04 2013
@@ -277,6 +277,9 @@ public class WebappClassLoader extends U
protected boolean delegate = false;
+ private final HashMap<String,Long> jarModificationTimes = new HashMap<>();
+
+
/**
* The list of JARs, in the order they should be searched
* for locally loaded classes or resources.
@@ -839,41 +842,36 @@ public class WebappClassLoader extends U
}
}
- length = jarNames.length;
// Check if JARs have been added or removed
- if (getJarPath() != null) {
-
- WebResource[] jars = resources.listResources(getJarPath());
+ WebResource[] jars = resources.listResources("/WEB-INF/lib");
+ if (jars.length > jarModificationTimes.size()) {
+ log.info(sm.getString("webappClassLoader.jarsAdded",
+ resources.getContext().getName()));
+ return true;
+ } else if (jars.length < jarModificationTimes.size()){
+ log.info(sm.getString("webappClassLoader.jarsRemoved",
+ resources.getContext().getName()));
+ return true;
+ }
- int i = 0;
- int j = 0;
- for (; j < jars.length && i < length; j++) {
- // Ignore non JARs present in the lib folder
- String name = jars[j].getName();
- if (!name.endsWith(".jar"))
- continue;
- if (!name.equals(jarNames[i])) {
- // Missing JAR
- log.info(" One or more JARs have been added : '"
- + name + "'");
+ for (WebResource jar : jars) {
+ if (jar.getName().endsWith(".jar") && jar.isFile() &&
jar.canRead()) {
+ Long recordedLastModified =
jarModificationTimes.get(jar.getName());
+ if (recordedLastModified == null) {
+ // Jars have been added and removed
+ log.info(sm.getString("webappClassLoader.jarsAdded",
+ resources.getContext().getName()));
return true;
}
- i++;
- }
- if (j < jars.length ) {
- for (; j < jars.length; j++) {
- // Additional non-JAR files are allowed
- if (jars[j].getName().endsWith(".jar")) {
- // There was more JARs
- log.info(" Additional JARs have been added");
- return true;
- }
+ if (recordedLastModified.longValue() != jar.getLastModified())
{
+ // Jar has been changed
+ log.info(sm.getString("webappClassLoader.jarsModified",
+ resources.getContext().getName()));
+ return true;
}
- } else if (i < jarNames.length) {
- // There was less JARs
- log.info(" One or more JARs have been removed");
- return (true);
+ jarModificationTimes.put(
+ jar.getName(), Long.valueOf(jar.getLastModified()));
}
}
@@ -1517,6 +1515,8 @@ public class WebappClassLoader extends U
for (WebResource jar : jars) {
if (jar.getName().endsWith(".jar") && jar.isFile() &&
jar.canRead()) {
addURL(jar.getURL());
+ jarModificationTimes.put(
+ jar.getName(), Long.valueOf(jar.getLastModified()));
}
}
@@ -1553,6 +1553,7 @@ public class WebappClassLoader extends U
started = false;
resourceEntries.clear();
+ jarModificationTimes.clear();
resources = null;
jarRealFiles = null;
jarPath = null;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]