This was a problem with JBoss until recently, due to
a caching problem.
The Class gets cached for performance reasons but
it never gets uncached at undeployment.
Have a look at
http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t=forums/ fix was applied in 2.4.4-17 on 28/Nov/01
Warning 2.4.4 is currently a beta release.
Thanks for the info, Adrian!
I know this is a lame question, but is there some kind of a release date planned for jBoss 2.4.4 or maybe even for 3.0?
I am a bit leary of using beta software for production environment :)
I don't know. Maybe Scott Stark can answer this?
Interestingly, part of the fix isn't in 3.0 yet.
I tried 2.4.4-20 and my static variables still do not get finalized.
Basically, I am using a singleton pattern. I put debugging print statements into both a constructor and finalize() methods. I see a constructor being called on every redeployment but I never see finalize() invoked.
I know I am not supposed to rely on finalize() being called at a certain time, but shouldn't it be called eventually?
It does get called eventually...
I wouldn't rely on the finalizer being invoked before
redeployment, because it won't be.
When I was testing the OutOfMemory problem, there were sometimes hundreds of unused copies of the Stateless Session Bean lying around in the heap waiting for the garbage collector to tidy them up.
There is no portable way of doing things at undeployment of a bean. The specification doesn't cover this.
What type of resources are you caching?
Is it important that they are not released until next Tuesday? :-)
From the EJB spec:
"An enterprise Bean must not use read/write static fields. Using read-only static fields is allowed. Therefore, it is recommended that all static fields in the enterprise bean class be declared as final."
In other words DON'T do what you are doing.
Try changing your cache to an Entity Bean with Bean managed persistence.
Thanks again for following up with more advice.
Here are the ugly details of my problem - I am using TopLink (www.webgain.com) for transarent JavaBean persistance management (note, not Entity EJB's but JavaBeans). Unfortunately, it's THEIR class that has the static member variable, thus violating the spec, as you kindly pointed out. They provide their own implementation of database pooling. After ten or so redeployment (during heavy development process) my database runs out of available connections and I have to restart jBoss. The problem multiplies by the fact that I am not the only developer in the company doing the same thing.
I guess I will be contactig TopLink people...
The funny thing (well, not so funny to me at the moment) is that particular class is in a package created specifically for EJB container integration...
Adrian, thanks again for all of your advice!
you can use the jboss data source and configure the toplink to use external data source
How do you do this? I've seen you reference using an external data source for TopLink in a couple of posts, do you have a configuration example?