[jboss-user] [EJB 3.0] - @PostConstruct and @PreDestroy in JBoss AS 5.0.0CR2

aojensen do-not-reply at jboss.com
Mon Sep 22 05:38:54 EDT 2008


I have started deploying an internal Java EE ejb application of ours in the new JBoss AS 5.0.0CR2, due to the fact that -- as far as I can see -- JBoss 4.x does not support the complete set of features in EJB 3.0. The application was previously developed for Glassfish, but we've decided moving to JBoss for several other technical reasons. 

This question might be a bit complex .Please tell me if you want snippets of the source codes and the beans that we've produced -- I can put it up to a pastie. 

I am developing a simple mail daemon/service) that looks up new entries in a table called mail_events (mapped to an EJB entity called MailEvent). The service runs as a while loop in a separate thread that loads new MailEvents from the database and processes each message according to a template (e.g. sends out a mail to a newly registrated user with login information). I considered using JMS, but this is not possible due to several environmental issues (we depend on other legacy applications that do not speak JMS -- hence we just use a relational database). 

Currently I have made a EJB called QueueExecuterBean that is a stateless session bean which implements QueueExecuterLocal. This bean loads a singleton class, QueueRunner which extends java.lang.Thread. Hence, QueueRunner is the aforementioned thread that polls for new entries in the MailEvents table (using a proper Facade). 

QueueExecuterBean which holds the reference to QueueRunner should be started AS SOON AS the application is deployed. Therefore I've added two methods: 

public void initialize()


public void exit()

-- according to the EJB 3.0 specification. 

Nevertheless, when deploying the bean, none of the methods were invoked. Subsequently I tried deploying a servlet that is loaded upon start-up. This servlet refers the QueueExecuterLocal using @EJB annotations -- and invokes a dummy method on the bean in the servlet's init() method. This causes the @PostConstruct annotated method to be called. 

My problem is that the exit() method in the bean is never called. I cannot control nor find out when the bean is shut down. Tihs is a big problem, since I need to ensure that the queue is properly cleaned up and that the QueueRunner thread is properly stopped before undeploying the bean. 

How come this is such a big problem? Is it due to lack of conformance with the EJB 3.0 specification?

As such, I am open to other solutions regarding the service/daemon design and problem. I am not sure if this is the right solution to the problem.

Thanks in advance, 


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4177971#4177971

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4177971

More information about the jboss-user mailing list