9 Replies Latest reply on Mar 15, 2002 9:15 AM by rols

    release resources on redeployment

    fgolos

      It seems that jBoss does not completely "throw away" old objects when a new jar file is deployed. I have a class with static reference to some resources I need to release on redeployment. How can I catch redeployment events? Or what is the correct way to deal with this situation?

      Just to clarify, it is not a resource on a per EJB basis, but rather one static reference to an object responsible for allocation and release of resources.

      Thanks, gang!

        • 1. Re: release resources on redeployment

          Hi,

          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.

          Regards,
          Adrian

          • 2. Re: release resources on redeployment
            fgolos

            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 :)

            Regards!

            • 3. Re: release resources on redeployment

              Sorry,

              I don't know. Maybe Scott Stark can answer this?

              Interestingly, part of the fix isn't in 3.0 yet.

              Regards,
              Adrian

              • 4. Re: release resources on redeployment
                fgolos

                Adrian,

                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?

                Thanks!

                • 5. Re: release resources on redeployment

                  Hi,

                  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? :-)

                  Regards,
                  Adrian

                  • 6. Re: release resources on redeployment

                    Hi,

                    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.

                    Regards,
                    Adrian

                    • 7. Re: release resources on redeployment
                      fgolos

                      Adrian,

                      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!

                      • 8. Re: release resources on redeployment

                        you can use the jboss data source and configure the toplink to use external data source

                        • 9. Re: release resources on redeployment
                          rols

                          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?