tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Phillip Morelock <>
Subject Re: ?? Class Loaders, Static Initializers, Open Files ??
Date Tue, 07 May 2002 07:14:11 GMT
Unfortunately I believe that's what static initialization is.

It's not totally clear whether this will help you, but here's a link 
that describes the order things are done in:


At Tuesday, 7 May 2002, you wrote:

>Hi all,
>This is a core Java language issue but its roots are in servlets.
>I have a servlet (running on Tomcat v4.0.3), MyServlet, which
>calls Class.forName("XXX") in it's init() method.
>Now class XXX has a static initializer that opens a file for
>output and keeps it open. Later, I change the code in MyServlet
>and recompile it. The Tomcat notices the change and automatically
>loads the new version of MyServlet, using a different class
>loader than was used for the previous version.
>But when the new version of MyServlet calls Class.forName("XXX"),
>the static initializer in XXX cannot open the file because the
>previous version has it open.
>So even though the first class loader is being
>"dropped/abandoned", there is still a class loaded by that class
>loader (class XXX) that has a file open. And of course, I do not
>have the code for XXX.
>Is there any way to specify, either to the JVM or to Tomcat, that
>the file opened by XXX's static initializer should be closed? I'm
>guessing this is "just the way it works". The previous class
>loader will be GCed, as will the previous version of MyServlet,
>but the file opened by XXX stays open until the VM goes down...
>To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.>
>For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.>

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message