• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A backend service

 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I'm not sure if I approve of this interruption. But this tiny ad checks out:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic