I need to write a component to sit on the server and check some records in a database every hour. I need this component to run on the server 24 hrs a day. If the component finds a record that meets a certain criteria, then it will send off an e-mail.
The question that I have is what is the best architecture for this component. I thought about just putting a servlet on the webserver and make that check the DB every hour, but there must be a better way.
Thanks
-
e-mail component running 24x7 (3 messages)
- Posted by: chad bruggemann
- Posted on: August 16 2002 15:49 EDT
Threaded Messages (3)
- e-mail component running 24x7 by Lasse Koskela on August 18 2002 07:09 EDT
- e-mail component running 24x7 by Web Master on August 18 2002 11:28 EDT
- e-mail component running 24x7 by Reynir Hubner on August 19 2002 12:40 EDT
-
e-mail component running 24x7[ Go to top ]
- Posted by: Lasse Koskela
- Posted on: August 18 2002 07:09 EDT
- in response to chad bruggemann
I wouldn't use a servlet for this job (it's not what servlets are for).
In my opinion, you have two viable options:
1. launch a standalone java program using an OS-specific timer (e.g. cron in unix).
2. start a standalone java program upon server startup and use the standalone program's thread to wake up and send emails once in an hour.
I would opt for the second approach, but that's just because I'm a bit suspicious about using operating system specific stuff... -
e-mail component running 24x7[ Go to top ]
- Posted by: Web Master
- Posted on: August 18 2002 11:28 EDT
- in response to Lasse Koskela
I agree with Lasse. Check out java.util.Timer and java.util.TimerTask.
notsew -
e-mail component running 24x7[ Go to top ]
- Posted by: Reynir Hubner
- Posted on: August 19 2002 12:40 EDT
- in response to chad bruggemann
Hi, because you mentioned Serlvet, you should not implement a servlet to do this, rather implement a ServletContextListener, that runs a thread that does this on any interval you want. That way you can be sure the thread runs while your ServletContext is running and is deleted if the ServletContext dies, (garbage collected).
At least because you're thinking of implementing a servlet to do this, this should be more correct way for you to deal with threads running as a part of an WebApplication.
hope it helps
-reynir