• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Loading cache during tomcat server start up

 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Rancher
Posts: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic