2

This app must perform connection to a web service, grab data, save it in the database. Every hour 24/7. What's the most effective way to create such an app in java?

How should it be run - as a system application or as a web application?

6 Answers 6

7

Keep it simple: use cron (or task scheduler)

If that's all what you want to do, namely to probe some web service once an hour, do it as a console app and run it with cron.

An app that starts and stops every hour

  • cannot leak resources
  • cannot hang (may be you lose one cycle)
  • consumes 0 resources 99% of the time
2
2

look at quartz, its a scheduling library in java. they have sample code to get you started. you'd need that and the JDBC driver to your database of choice. no web container required - this can be easily done using a stand alone application

2
  • 2
    quartz is overkill for a single task that starts once an hour
    – flybywire
    Mar 1, 2010 at 11:49
  • maybe, maybe not, but at least its reliable, as opposed to the jre-provided timer facilities
    – radai
    Mar 3, 2010 at 20:42
2

Try the ScheduledExecutorService.

1
  • But you need to ensure that your process is up and running in the first place.
    – omerkudat
    Mar 1, 2010 at 13:04
0

Why not use cron to start the Java application every hour? No need to soak up server resources keeping the Java application active if it's not doing anything the rest of the time, just start it when needed,

0

If you are intent on doing it in java a simple Timer would be more than sufficient.

0

Create a web page and schedule its execution with one of many online scheduling services. The majority of them are free, very simple to use and very reliable. Some allows you to create schedules of any complexity just like in cron, SqlServer job UI, etc. Saves you a LOT of headache creating/debugging/maintaining your own scheduling engine, even if it's based on some framework like Ncron, Quartz, etc. I'm speaking from my own experience.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.