views:

264

answers:

2

I'd like to create a queue monitoring container-managed component in a Java EE 5 app. The queue is a database table and every 5 mins or so the monitor would look for records that match certain criteria in that table. If there are any matching records, the monitor starts some kind of processing in a new thread. This sleep-check-do work loop should continue as long as the app is started and occur independently of any client session.

What EJBs, Servlet, etc... should I be looking at to implement this kind of thing? I'm using Websphere 7, but ideally the solution wouldn't be tied to any one app server. Also, JMS is not an option. If this isn't straightforward to implement with Java EE container-managed components, what other ways make sense?

Thanks.

+2  A: 

EJB3 with Timer Services. Something like this:

@Stateless
class MyBeanImpl implements MyBean {

    @Timeout
    public void myTimedOutMethod(Timer timer){

    }
}
dfa
+1  A: 

It is not a good idea to start your own threads in a Java EE container. In Websphere you could use Java EE Timers. If you want a solution that will also work in Tomcat for example, you can use Quartz.

kgiannakakis