Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Timers

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have a simple banking web application that allows users to deposit/withdrawal/transfer money to each other.

I'd like the application to run a task every 3 days or so automatically which can add interest to the customers accounts,
or charge accounts in debt.

I'm not sure of the best way of doing this, any ideas?
Thanks
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can't we use it programmatically? And, I think, it's not specific to servlets.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suppose I could load a servlet (after application has been started), which has a java.util.Timer.

The get method could then start the timer up.

Or perhaps passing "START", "STOP" as a request paramter, to start or stop the timer.

Is this a good idea?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't you have some sort of "administrator" servlet you can use to check the operation of the whole thing?

That would be the obvious place to put automatic operations - but i would not depend entirely on a timer that would be thrown off every time the app was stopped and restarted.

Bill

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I don't. Any suggestions
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So how would I start a timer up when the web app is started?

I'm thinking of implementing ServletContextListener in a normal java class,
Then get this to start the timer
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best option to achive this , would be using Job Schedulers like cron .
Go through this cron and let me know , if you have any queries , because we implemented this way only in our previous Application .

Thanks .
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11888
203
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravi Kiran Va wrote: The best option to achive this , would be using Job Schedulers like cron .

While cron is an option if Colin is on a *nix system (he doesn't specify). I don't know that I would call it the best option. I dislike having an external system that has to be maintained concurrently with the main system. Especially one that would have completely different setup instructions for the person deploying the system, and one that would introduce far more complexity in ensuring that there are no race conditions or conflicts in the two separate systems both modifying the same database tables and fields.

Personally I would look at the Timer class, or one of the packages that replace cron (e.g. cron4j, or quartz)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic