I am planning to use HashMap my in-memory caching in my application. Our application server is clustered. Whether this HashMap will work in multi-threaded environment ? If not, can i change my implemnetation to HashTable for multi-threading support. How is the performance using HashMap/HashTable in a clusteered environment ?
I think you are talking about 2 separate issues here. Being thread-safe is when you code needs to be changed by more than one process simultaneously in one JVM i.e. in a multi-threaded environment. Having your objects safe in a clustered environment is a different matter. I haven't looked at this in a while, so I don't know if built-in jvm support exists now or not. I would suggest not rolling your own and looking for some form of open source or commercial object cache that will do what you want. I googled 'distributed object cache'. This should get you started.
You could just use java.util.concurrent.ConcurrentHashMap and be done with it (for the concurrent part, not the clustered part). Any modern clustered Map will probably implement ConcurrentMap anyway, so you'll just have to change the implementation.
Joined: Apr 08, 2004
Can i use eCache or Oracle coherent caching for storing database values ?
Joined: Jul 20, 2010
Ehcache is commonly used to cache the results of database queries: for example, it's frequently used as the second level cache for Hibernate. It's easily plugable, has lots of configuration options (region sizes, overflow to disk, time to live, time to idle, eviction strategy, etc.), can be extended (self-populating caches) and clustered with Terracotta.
As far as I know, Oracle Coherence can be used too, but in that case I hope you wouldn't use it only as a local cache, since Ehcache easily provides the same service for free.