File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes A backend service Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "A backend service " Watch "A backend service " New topic
Author

A backend service

Em Aiy
Ranch Hand

Joined: May 11, 2006
Posts: 226
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?


The difference between <b>failure</b> and <b>success</b> is often being <b>right</b> and being <b>exactly right</b>.
Roland Maurer
Greenhorn

Joined: Nov 23, 2008
Posts: 17
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

Joined: Oct 30, 2007
Posts: 114
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

Joined: Mar 22, 2000
Posts: 12806
    
    5
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

Joined: Sep 30, 2008
Posts: 198
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.


My Blog
Srikanth Nutigattu
Ranch Hand

Joined: Oct 30, 2007
Posts: 114
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

Joined: Apr 14, 2004
Posts: 10336


-Quartz for Scheduling

Quartz is a pretty full-on scheduling solution. I'd only recommend using it if you have quite involved scheduling needs.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A backend service