TimerTask in Struts for handling Stored Procedures.
Joined: Oct 19, 2005
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?
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.