views:

291

answers:

2

I have a managed bean / service running inside of JBOSS. I then have a quartz job that will occasionally wake up and call a method of the managed bean. This method is sometimes long and drawn out, and since I don't want the quartz job to time out, I have implemented a thread within the managed bean to perform the processing. When the thread is finished I need to update a database table with the results. This is a very serial process and it needs to be based upon some business rules, etc.

My main question is that I can use an EntityManager within the service without a problem however I can not use it from within the thread, I get a NullPointerException. What would be the best way to address this?

Thanks,

Scott

A: 

As creating threads in appservers is discouraged, I'd modify the setup a bit.

I'd move the core of processing to a message driven bean, and have the Quartz job just send a message to the queue on which the MDB is listening. The MDB in turn can call your EJB, and like this everything remains within what's allowed by the standard.

fvu
This was the original way that I had it set up however the long process would timeout the MDB bean and/or the EJB. What I eneded up find was a way to annotate the EJB so that it would not timeout.
Scott Everts
A: 

As per the documentation and specification the Entity Manager is not thread safe and can not be used across different child threads as I had originally had in mind. I ended up going back to the original design similar to the one provided by fvu, however I found some annotations that would allow me to modify the been timeout period and allow the long running process to work properly. Here's the annotation that I used:

@PoolClass(value=org.jboss.ejb3.StrictMaxPool.class, timeout=360000000L)
Scott Everts
That timeout is 3600 seconds * 1000 milliseconds * 100 HOURS??? That's some long-running bean you have ;-)
fvu