Link Details

Link 817751 thumbnail
User 744713 avatar

By hstaudacher
Published: Jul 09 2012 / 19:49

I can’t count the number of times I found myself implementing some sort of cache. In many situations caching is really useful e.g. when the computation of a value is expensive or when loading of resources is involved. I bet you found yourself implementing a cache many times too. Probably you have also used a Java Map for storing the values. One disadvantage of using Maps for caching is that you have to implement the eviction of entries yourself, e.g. to keep the size to a given limit. When you develop for a concurrent environment the task gets more complicated and a simple Map is not sufficient. You need to switch to a thread safe solution, e.g. a ConcurrentHashMap. ConcurrentHashMaps solve the concurrency problem, but the code gets ugly. You have to deal with the fact that keys can be added multiple times from different threads concurrently.
  • 20
  • 0
  • 2639
  • 2098


Add your comment
User 236075 avatar

henk replied ago:

0 votes Vote down Vote up Reply


Add your comment

Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Spring Integration
Written by: Soby Chacko
Featured Refcardz: Top Refcardz:
  1. Search Patterns
  2. Python
  3. C++
  4. Design Patterns
  5. OO JS
  1. PhoneGap
  2. Spring Integration
  3. Regex
  4. Git
  5. Java