* Johan Compagner:
> First of all you also should do that in the lastModifiedTime
> call of the URLResourceStream class.
Right, thanks for pointing out. The problem is more serious than
I thought first, because the file descriptor leak also happens in
DEPLOYMENT mode, although a lot less.
In DEVELOPMENT mode templates in JAR files are checked every
second (by default), so file leaking is very quick. But in
DEPLOYMENT mode, it's only when loading other resources (CSS, JS,
images) that the leak occurs. And because of browser caching you
don't notice the leak a lot.
I have a very radical solution to that: prevent to update the last
modified time for resources in JARs as it doesn't make a lot of
sense anyway to reload resources from JARs. I couldn't figure out
a more elegant approach.
Please find patch attached. If you think it's worth, I'll add it
to the SF tracker.
--
Jean-Baptiste Quenot
aka John Banana Qwerty
http://caraldi.com/jbq/
Index: src/java/wicket/util/resource/UrlResourceStream.java
===================================================================
--- src/java/wicket/util/resource/UrlResourceStream.java (revision 7162)
+++ src/java/wicket/util/resource/UrlResourceStream.java (working copy)
@@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
+import java.net.JarURLConnection;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
@@ -79,24 +80,29 @@
URLConnection connection = null;
try
{
- connection = url.openConnection();
- contentLength = connection.getContentLength();
- contentType = connection.getContentType();
- lastModified = connection.getLastModified();
- try
+ file = new File(url.getFile());
+ if (!file.exists())
{
- file = new File(new URI(url.toExternalForm()));
+ file = null;
}
- catch (Exception ex)
+ if (file != null)
{
- log.debug("cannot convert url: " + url + " to
file (" + ex.getMessage()
- + "), falling back to the
inputstream for polling");
+ log.debug("Using file " + file + " to poll for
changes");
+ return;
}
- if (file != null && !file.exists())
- {
- file = null;
- }
}
+ catch (Exception ex)
+ {
+ log.debug("cannot convert url: " + url + " to file (" +
ex.getMessage()
+ + "), falling back to the URLConnection
for polling");
+ }
+ try
+ {
+ connection = url.openConnection();
+ contentLength = connection.getContentLength();
+ contentType = connection.getContentType();
+ lastModified = connection.getLastModified();
+ }
catch (IOException ex)
{
// It should be impossible to get here or the original
URL
@@ -233,13 +239,19 @@
try
{
urlConnection = url.openConnection();
-
- // update the last modified time.
- long lastModified =
urlConnection.getLastModified();
- if (lastModified != this.lastModified)
+
+ if (urlConnection instanceof JarURLConnection) {
+ log.warn("Not updating lastModified
because resource is in a JAR: " + url);
+ }
+ else
{
- this.lastModified = lastModified;
- this.contentLength =
urlConnection.getContentLength();
+ // update the last modified time.
+ long lastModified =
urlConnection.getLastModified();
+ if (lastModified != this.lastModified)
+ {
+ this.lastModified =
lastModified;
+ this.contentLength =
urlConnection.getContentLength();
+ }
}
}
catch (IOException e)
@@ -255,7 +267,7 @@
{
((HttpURLConnection)urlConnection).disconnect();
}
- else
+ else if (! (urlConnection instanceof
JarURLConnection))
{
try
{
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Wicket-develop mailing list
Wicket-develop@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-develop