Win a copy of Practice Tests for OCP Java 17 Certification Exam (1Z0-829) this week in the OCPJP forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Timers

 
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
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
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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, I don't. Any suggestions
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
author and jackaroo
Posts: 12199
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic