aspose file tools*
The moose likes Java in General and the fly likes timed actions in web app Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "timed actions in web app" Watch "timed actions in web app" New topic
Author

timed actions in web app

Martas Walter
Greenhorn

Joined: Dec 28, 2011
Posts: 5
Hi,
I am working on simple web application using spring + hibernate + postgreSQL. I need to find out some way to let my app do an action on date and time saved in db. For example I have user birthdate record in DB and I want system to send an email to the user on his birthday. I've been thinking about letting timer thread to ask db every few minutes if there are date records matching to current date and time. But I have no experience with concurency in Java EE, so I am not sure if it is the right way. Or are there some other tools in spring and hibernate which could help me? I just need an advice on how to do this simply and gently to server.
Many thanks in advance.
Joe Areeda
Ranch Hand

Joined: Apr 15, 2011
Posts: 316
    
    2

Hi Martas,

I'm not familar with Spring and Hibernate but since nobody responded yet allow me to offer an alternative.

It seems as though you only need to run the mailer once a day. So I ask why do it from the web app itself?

I would tend to run a separate program as a cron job (or the Windows alternative) that searched the database for birthdays. The db will have no problems with the concurrency.

If you want to do it from inside your web app, you may want to look at http://www.ibm.com/developerworks/java/library/j-schedule/index.html which discusses the issues.

Joe


It's not what your program can do, it's what your users do with the program.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61043
    
  66

I agree with Joe. Such things are better handled in a daemon program running separately from the web application.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Martas Walter
Greenhorn

Joined: Dec 28, 2011
Posts: 5
Thank you for responses. I am going to try the solution with daemon.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41571
    
  54
It may still make sense to keep the code as part of the web app, though. In which case you could set up a Timer and a TimerTask in a ContextListener. But if you can easily separate it out into a cron job, I'd go for that.


Ping & DNS - my free Android networking tools app
 
 
subject: timed actions in web app