using ServletContextListener for background process in tomcat, problems?
843842Jun 27 2010 — edited Jun 28 2010Hi, I am building a web app using mojarra 1.2, hibernate 3.2, mysql 5 and tomcat 6. Currently, there's a need to run a background process every hour to:
1) query the database
2) process information
3) send emails to (big) list of individuals when matched
4) update database
5) must happen during business hour
For now, my approach to this problem is to hook a Timer object inside a class implements ServletContextListener. So that every hour during business hour will process the steps above when Tomcat started until someone shut down shut down Tomcat or when it crash (hopefully that won't happen).
I read a few articles, they claimed this is not a good approach because in a managed environment, background thread like this won't be in the scope of the container.
Due to certain reasons, we can't deploy this part as a separate daemon (e.g: jsvc) yet. We'll need to wait for few other things to occur before can we deploy a full daemon services.
The question for this post is: What are some of the potential problems we will be dealing with when running background thread like this in tomcat? What are some of the things we'll need to watch out for before real problems arise (e.g size of db connection, # of concurrent process, etc) what are some other pitfalls other experienced when deploying background thread in tomcat?
We hope this solution will be able to handle what needs to be done until our daemon service is ready.
Thank you for your opinions