File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Timers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Timers" Watch "Timers" New topic
Author

Timers

colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
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

Joined: Nov 04, 2009
Posts: 2066

Can't we use it programmatically? And, I think, it's not specific to servlets.


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
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

Joined: Mar 22, 2000
Posts: 12781
    
    5
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

Joined: Apr 11, 2005
Posts: 744
No, I don't. Any suggestions
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
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

Joined: Apr 18, 2009
Posts: 2234

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 .

Save India From Corruption - Anna Hazare.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11460
    
  94

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)


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Timers