• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A backend service

 
Em Aiy
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to build a utility, which will reside in my application server and will run, regularly after particular interval, say 30 Min. read data from some webpage and then email the extracted information of that page.

My question is, how can i make a java class to run/execute after particular interval of time? regularly!

should i make it a servlet and put it in application server or it should be normal java class?
 
Roland Maurer
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can do something like that:


if you are inside a J2EE Application you can use the Timer service .

http://www.onjava.com/pub/a/onjava/2004/10/13/j2ee-timers.html
 
Srikanth Nutigattu
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For simple task without any "bells and whistles" you can use the Timer class, But my recommendation would be to use the following

### For Scheduling i.e executing the tasks at a particular intervals or at a specific point of time:

1. Use Quartz which is a scheduling framework, it also supports very advanced features if you want.

http://www.opensymphony.com/quartz/

### For Mailing from your application you can use Java Mail API.
This API is highly flexible and powerful for your mailing needs.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If this was my problem I would create a servlet which provided for starting, stopping and monitoring this service thread. Naturally this monitor servlet would have restricted access.

Think of all the things that could go wrong - the site you are scraping could go down, the email server could go down, etc. - you really need to be able to check on this.

The monitoring servlet could even keep a copy of the most recent sucessful report.

Bill
 
Vinod K Singh
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The kind of app stand alone or web app depends on the requirement or the way you want to use that. java.util.Timer / TimerTask, javax.ejb.TimedObject along with 'java.util.concurrent' package should of be your interest.
 
Srikanth Nutigattu
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The decision to create everything from scratch or use the existing and proven technologies depends on the requirements.

But, as far as I can see using,

-Quartz for Scheduling
-Log4J for logging
-JavaMail for Mailing

would be ideal choice for complex applications.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

-Quartz for Scheduling

Quartz is a pretty full-on scheduling solution. I'd only recommend using it if you have quite involved scheduling needs.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic