Link Details

Link 817751 thumbnail
User 744713 avatar

By hstaudacher
via eclipsesource.com
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
  • 2804
  • 2101

Comments

Add your comment
User 236075 avatar

henk replied ago:

0 votes Vote down Vote up Reply

Nice!

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.

Play Framework
Written by: Ryan Knight
Featured Refcardz: Top Refcardz:
  1. Akka
  2. Design Patterns
  3. OO JS
  4. Cont. Delivery
  5. HTML5 Mobile
  1. Akka
  2. JUnit/EasyMock
  3. Java Performance
  4. REST
  5. Java