• Post Reply Bookmark Topic Watch Topic
  • New Topic

creating a persistent object at load time?  RSS feed

 
Phil Chuang
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Say I have an object I want to make available server-wide, and instantiated when tomcat starts up... How would I do this?
I have a hash of numbers to strings that is in a database, I'd like to load the values from the DB and make it available to all jsps and servlets so I don't have to hit the DB all the time.
 
Andy Bowes
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The easiest way to acheive this is to perform the opertaion in the init() method of a servlet that is flagged in the web.xml as being loaded on start up.
i.e.

Hope this helps
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And then a great way to make it available to everything else is to store it as an attribute on the servlet context.
hth,
bear
 
Phil Chuang
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You guys rock, thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!