Thank you all for the replies. The unfortunate part of this is
that my servlet runs in a shared Tomcat environment so I don't
have the luxury of putting classes/JARs wherever I want.

I *will* be able to but some code in the destroy() method to
inform the XXX class that it should close the file. I was just
wondering if there was a better way..

Thanks again.




----- Original Message -----
From: "Cox, Charlie" <[EMAIL PROTECTED]>
To: "'Tomcat Users List'" <[EMAIL PROTECTED]>
Sent: Tuesday, May 07, 2002 8:05 AM
Subject: RE: ?? Class Loaders, Static Initializers, Open Files ??


> you can move it to \common\lib which is loaded by a different
class loader,
> but then it will be visible to all contexts.
>
> Using a static initializer like that will also cause problems
if you try to
> use the manager to control your app since manager drops the
classloader and
> creates a new one when you reload.
>
> maybe instead of a static initializer, you can use a servlet's
init() and
> have it load on startup. This way you can use a class and
utilize the
> destroy() method to do your cleanup.
>
> Charlie
>
> > -----Original Message-----
> > From: tamir [mailto:[EMAIL PROTECTED]]
> > Sent: Tuesday, May 07, 2002 3:36 AM
> > To: 'Tomcat Users List'
> > Subject: RE: ?? Class Loaders, Static Initializers, Open
Files ??
> >
> >
> > Hi Tony,
> > Here is my notion:
> > What you're using is tomcat automatic class reloading. When
> > you compile
> > class MyServlet tomcat
> > drop it's current class loader and creates a new one which
> > loads all your
> > classes again.
> > I think, if you should try to remove you class XXX outside of
> > web-inf/classes and
> > put it tomcat_home/common/lib in a jar.
> > Then, tomcat won't reload your XXX class, and your static
> > file will be ok.
> > try it.
> >
> > Tamir
> >
> > -----Original Message-----
> > From: Tony LaPaso [mailto:[EMAIL PROTECTED]]
> > Sent: Tuesday, May 07, 2002 8:25 AM
> > To: [EMAIL PROTECTED]
> > Subject: ?? Class Loaders, Static Initializers, Open Files ??
> >
> >
> > 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...
> >
> > Thanks...
> >
> >
> >
> >
> >
> > --
> > To unsubscribe, e-mail:
> > <mailto:[EMAIL PROTECTED]>
> > For additional commands, e-mail:
> > <mailto:[EMAIL PROTECTED]>
> >
> > --
> > To unsubscribe, e-mail:
> > <mailto:[EMAIL PROTECTED]>
> > For additional commands, e-mail:
> > <mailto:[EMAIL PROTECTED]>
> >
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to