my dog learned polymorphism
The moose likes EJB and other Java EE Technologies and the fly likes Background process in EJB Architecture? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Background process in EJB Architecture?" Watch "Background process in EJB Architecture?" New topic

Background process in EJB Architecture?

Andrew Keidel

Joined: Dec 06, 2001
Posts: 27
I'd like to run a background process in my company's ejb architecture to update entity beans periodically. For example, I'd like to update an entity bean with any new database table rows once every 10 minutes.
I've read that bean-managed threads are not supported in EJB, so how can I do this?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17423

Write a client application to touch the EJBs. One way to do that is to write a "null" servlet - one that does all its work in the init() method instead of doGet/doPost. Let init() spawn a thread that wakes up every 5 minutes, reads the rows of interest, and then updates the EJBs.
CAUTION: If the EJBs are being updated by other sources as well, you'll have to work out a conflict resolution scheme. Otherwise you'll end up undoing changes!

An IDE is no substitute for an Intelligent Developer.
Dave Van Even
Ranch Hand

Joined: Jul 19, 2001
Posts: 101
Here's an article ( ) about the first public draft of the Enterprise JavaBeans 2.1 specification and look what we've got there
Timer Service
The Time Service is a scheduling system that is built into the EJB container. A stateless session or entity bean can register itself with the Timer Service, and request notification at a particular point in time or when a specified period of time has elapsed.
The Timer Service uses a fairly simple programming model. The stateless or entity bean must implement the TimedObject interface.

When the bean's timer goes off, the container will call its ejbTimeout() method. You can put any kind of business logic you like in ejbTimeout(). For example, an entity bean that represents an invoice might have a timer that activates after 45 days. When the timer goes off, the container calls the ejbTimeout() method. The Invoice entity bean might then send a JMS message to alert an accounts-receivable application that payment is overdue, or send the customer an e-mail requesting payment.
Dunno how long it will take till we can actually use this ? Anyone ?

Dave Van Even
I agree. Here's the link:
subject: Background process in EJB Architecture?
It's not a secret anymore!