0 Replies Latest reply on Jun 14, 2007 7:34 AM by stwhit

    Cleanup code in Stateless Session Bean when JBoss shuts down

    stwhit

      I've written a simple stateless session bean with the following interface:

      @Remote
      public interface Foo {
       void sayHello();
      }


      and the following implementation:

      @Stateless
      public class FooBean implements Foo {
      
       @PostConstruct
       public void postConstruct() {
       System.out.println("Inside postConstruct");
       }
      
       @PreDestroy
       public void preDestroy() {
       System.out.println("Inside preDestroy");
       }
      
       public void sayHello() {
       System.out.println("Hello world");
       }
      }


      When I call the sayHello() method from a client, I see the following output:

      06:19:16,150 INFO [STDOUT] Inside postConstruct
      06:19:16,170 INFO [STDOUT] Hello world


      When I shutdown JBoss, however, I do not see "Inside preDestroy" printed to the screen.

      So, my question is two-fold:

      Does the @PreDestroy callback get called when JBoss is shutdown? (I would have expected it to, but apparently it does not..?)

      If @PreDestroy does not get, how/where can I put cleanup code in my beans that will get executed when JBoss shuts down?

      Thanks!