7 Replies Latest reply on Oct 22, 2010 7:52 AM by mikka2010

    removalTimeoutInSeconds & subsequent removal?

      We have a case where we would like to use EJB3 SFSBs, and the bean I have written is basically a proxy to a socket client. This means that one of the class' members is a Socket.

      We also have the case that we do not need to be able to recall the same session bean after the bean has been removed, so passivating the bean does not make sense in our case.

      Because of this, I have made the removalTimeoutInSeconds less than the idleTimeout, so the bean is removed and not passivated. I have tested this out and it works fine, until...

      If I close my client the wrong way (kill the task from task manager), the bean gets to the timeout when it should be removed. When I watch the JMX console to see what is going on, the numbers change like I expect them to, the passivated count is zero and the active count is zero. So it looks like the bean was removed properly. If I go look at my socket client that the bean made the connection to (the target of Socket::connect), it only shows that the connection was made, it doesn't show that the connection was broken, as one would expect when a Socket object is destroyed.

      I have one of my bean's functions annotated with the @Remove tag, and if I close my EJB3 client the correct way, this function is called correctly. It only doesn't seem to get called when the bean is supposed to be removed.

      If this is unclear, let me know, I really need some help on this one. Thank you.

        • 1. Re: removalTimeoutInSeconds & subsequent removal?

           

          "Protuhj" wrote:
          ...It only doesn't seem to get called when the bean is supposed to be removed.


          i meant this to be, "It only doesn't seem to get called when the bean is supposed to be removed when it reaches the timeout set with removalTimeoutInSeconds"

          • 2. Re: removalTimeoutInSeconds & subsequent removal?

            I solved my problem by adding @PreDestroy to my destroy method as well as making my objects associated with my socket transient, and marking them with @Transient

            • 3. Re: removalTimeoutInSeconds & subsequent removal?

              Ok -- I am getting frustrated over this, I have marked my remove function with @Remove and @PreDestroy and @PrePassivate, idleTimeoutSeconds is 5, removalTimeoutSeconds is 10, my members are transient.

              It first times out and passivates, and calls remove on the Proper SFSB. It then tries to remove the bean using @PreDestroy 5 seconds later. When I redeploy my EJB to the app server, it calls my destroy method AGAIN, like it wasn't destroyed properly in the first place.

              If I don't have @PrePassivate, it will call my destroy method via the @PreDestroy annotation I guess, but since it was passivated, it is not the correct instance of the bean so it doesn't close the socket. Then when I redeploy the EJB it calls the my remove function on the proper bean. This doesn't seem to be working like it should.

              • 4. Re: removalTimeoutInSeconds & subsequent removal?

                If I then make my removalTimeoutSeconds less than the idleTimeoutSeconds and just have @PreDestroy and @Remove on my method, it doesn't even call my remove function until the EJB deployment is redeployed

                • 5. Re: removalTimeoutInSeconds & subsequent removal?

                  this is the AppServer 4.2.3.

                  • 6. Re: removalTimeoutInSeconds & subsequent removal?

                    So I think I have a solution that works, but it seems like a hack. I have to set my idle timeout to less than the removal timeout, which is not what I wanted to do. I wanted it to just remove my bean as soon as it hit became idle.

                    But since when you hit removalTimeoutSeconds it doesn't actually do any cleanup of the memory (it just removes the data from the disk cache), setting the idleTimeout higher than the removalTimeout per the wiki doesn't work.

                    Something definitely seems broken with the way this is implemented in JBOSS AS 4.2.3, I don't know if it is any different in 5.0, I assume not.

                    This is the way I want it to work:

                    Client gets bean
                    bean connects the socket
                    client crashes (in our setup, this may happen, you never know)
                    bean times out (removalTimeoutSeconds not idle)
                    some annotated function gets called (@Remove or @PreDestroy this doesnt happen right now)
                    my socket is closed properly since the function was called
                    the other end of the socket gets the closure notice

                    this is what happens:
                    client gets bean
                    bean connects the socket
                    client crashes
                    bean times out (removalTimeoutSeconds)
                    no function of mine gets called
                    <nothing until...> i redeploy the EJB and then the preDestroy on the bean gets called..

                    • 7. Re: removalTimeoutInSeconds & subsequent removal?
                      mikka2010

                      Hello,

                       

                      I have a similar problem.

                      I use a stateful session bean with a removalTimeoutSeconds = 60 (for testing), but after the timeout the method annotated with @Remove is not executed.

                      Only the method annotated with @PreDestroy is called.

                      In the heap dump I can still see the session bean object in memory.

                       

                      I want to use the removalTimeout for such sessions which terminate abnormal.

                      If the client terminates normal, it calls the method annotated with @Remove and then the method annotated with @PreDestroy.

                      In this scenario the session bean object is not present in the memory anymore.

                       

                      I use the application server jboss 4.2.3_GA.

                       

                      Why is the remove method not called in case of a timeout and why does the object remain in memory?

                       

                      Kind regards

                      Huber