views:

277

answers:

6

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?

+2  A: 

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

hatchetman82
quartz is overkill for a single task that starts once an hour
flybywire
maybe, maybe not, but at least its reliable, as opposed to the jre-provided timer facilities
hatchetman82
A: 

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,

NeilInglis
+7  A: 

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
flybywire
Not everybody uses UNIX-alikes.
JUST MY correct OPINION
windows has the task scheduler
Valentin Rocher
+2  A: 

Try the ScheduledExecutorService.

Willi
But you need to ensure that your process is up and running in the first place.
omerkudat
A: 

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

denis
A: 

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.

Regina