File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Servlets
Bookmark "A backend service " Watch "A backend service " New topic

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

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 .
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.

### 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

Joined: Mar 22, 2000
Posts: 13037
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.

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

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:
subject: A backend service
It's not a secret anymore!