• Post Reply Bookmark Topic Watch Topic
  • New Topic

Loading cache during tomcat server start up  RSS feed

 
amit sanghai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have lots of objects that I want to cache just when the tomcat starts up. How can I do that?

Thanks ans regards,
Amit Sanghai.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make the cache ready as soon as the application starts up.To kick off you can use contextlistners.A simple cache can be implemented using HashMap.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ServletContextListener was made for executing code when your app starts up and shuts down.
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletContextListener.html
 
Amit M Tank
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another way is to invoke your servlet during deployment, by having the <load-on-startup>. So you have your cache instantiation code in the servlet which is loaded on the startup of the server. Hope this helps.



This is an outdated technique that has potential problems.
If you have a container that supports servlet spec 2.3 or better, it makes sense to use the feature that were written specifically for this purpose.
[ June 25, 2007: Message edited by: Ben Souther ]
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another way is to invoke your servlet during deployment, by having the <load-on-startup>.


Well, that's an outdated way of doing things - using a servlet to perform context-wide initializations is kind of icky. Go with the context listener.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!