This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android 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: 307
    
    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: 60785
    
  65

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: 41127
    
  45
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: timed actions in web app
 
Similar Threads
Trouble configuring Hibernate in Maven
save entity with SYSDATE
Batch processing threads in servlet enviornment
webservices - do I need application server?
Learn Spring and Hibernate?