Java: Setting a timer for running job

Tags:
Java
I am having a servlet where timer is scheduled to run job for every 5 minutes. The duty of job is to get the count of files from the database, archive the file with today's date, coping the file from source to destination and send the email with positive subject if success. Now I want to have a timer set for both positive and negative subject simultaneously. Can anyone suggest how to do this?
1

Answer Wiki

Thanks. We'll let you know when a new response is added.

If you’ve ever sat mesmerized by the spinning Java compiler, you’re not
alone. To set a timer for running a job or task in Java, create a timer
using the code Timer timer = new Timer();. Then, schedule the timer to
run the task. If you want to place a limit on the amount of time Java
has to do the job, use the code “TimeoutException” and be sure to tell
Java to stop the task, otherwise it will continue trying to do it in the
background, using up your bandwidth.

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • Subhendu Sen
    If  this is on java ee, use container-provided job scheduling api for this. There is not so much information. However, you can go for this example for just an idea.
    www.onjava.com/pub/a/onjava/2004/10/13/j2ee-timers.html?page=2
    142,210 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: