• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

timed actions in web app

 
Martas Walter
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 331
2
Java Netbeans IDE Tomcat Server
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Joe. Such things are better handled in a daemon program running separately from the web application.
 
Martas Walter
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for responses. I am going to try the solution with daemon.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic