It's not a secret anymore!
The moose likes JSP and the fly likes TimerTask in Struts for handling Stored Procedures. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Reply locked New topic

TimerTask in Struts for handling Stored Procedures.

Thierry Collogne

Joined: Oct 19, 2005
Posts: 16

I am developing a web application. In the application I have developed a timertask that is responsible for checking a table every 2 minutes. If a record in the table matches a condition, a SQL Stored procedure is called for that record.

So far no problem. The problem comes in the fact that multiple records can match the condition and the Stored Procedure takes some time to complete.
So for each matching record the procedure will be run.

So when 2 minutes have passed and the timertask again checks the database, it is possible that more and more records match the condition.

How can I make sure that the stored procedure is run for every record?
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Please do not cross post your questions.
You've already asked this in the Struts and Servlet forums.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

First off, please do not post the same question to multiple forums...

In answer to the question - unless the scheduled task that you're doing can be launched from your web application, or directly involves data in your web application that you can't get from the database, I'd suggest finding some other way of doing this than from a TimerTask inside your web application...

How can records get into the new "condition"? Why not update the records in response to this? (Of course, this may be beyond your control...)

Can your database schedule jobs? If so, I'd put the timing and job control there...

If you're stuck on controlling this from your web application, I'd then like to suggest using Quartz - it's pretty easy to get the hang of, and you won't have to muck around with threads and timer tasks directly...

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
I agree. Here's the link:
subject: TimerTask in Struts for handling Stored Procedures.
It's not a secret anymore!