This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Background process in EJB Architecture?

 
Andrew Keidel
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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?
Thanks,
Andy
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18020
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Dave Van Even
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's an article ( http://www.theserverside.com/resources/article.jsp?l=MonsonHaefel-Column1 ) 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic