This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "timed actions in web app" Watch "timed actions in web app" New topic

timed actions in web app

Martas Walter

Joined: Dec 28, 2011
Posts: 5
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: 331

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 which discusses the issues.


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

Joined: Jan 10, 2002
Posts: 63540

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

[Asking smart questions] [About Bear] [Books by Bear]
Martas Walter

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

Joined: Mar 22, 2005
Posts: 42959
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.
I agree. Here's the link:
subject: timed actions in web app
It's not a secret anymore!