• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

Object caching

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I want to keep a hash map of some object I am creating while some operation of my entity bean. I want this hashmap to be available across the whole application as long as the application runs. That is if I come back next time, I want that map be available. Now, my server is always running on a single jvm. The spec discourage me to use singleton/ static variables. So, where can I keep my hashmap? May be bind it in the Context()??
pls help.
Regards,
Sajid
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We use Singleton and static variables for exactly this purpose. Be aware that you don't get one per system or one per JVM but one per class loader. This is usually ok for read only stuff that is not too big to keep in memory. If you update the cache you'll need some way to make sure every darned copy of it gets changed. If your app has any potential to go to a cluster in the future, this could be a tricky bit. My current system can clear some or all cache data from an admin screen or via an API.

Look into open source or commercial caching solutions, especially if you need to synchronize distributed caches. There are interesting ways to go wrong on this stuff, and it's probably safer to get some code that's been running a long while than to make your own.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at "object cache" opensource implementation from Apache..
 
reply
    Bookmark Topic Watch Topic
  • New Topic