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
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.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi