Content
- Easy to use
- We will build a full JEE example in 15 minutes
- Standards compliant (soon)
- Powerful under the hood
- Dive into Infinispan's distribution mode
JCACHE - JSR 107
JSR 107 Core Interfaces
- CachingProvider: Configure CacheManagers
- CacheManager: Acquire Cache
- Cache: ConcurrentMap + eviction + backed by distributed topology
- Entry: Key-value pair
- Expiry
JSR 107 Timetable 2013
Deliverable | Start | Finish |
Public Review Ballot | 27 Aug | 9 Sep |
Proposed Final Draft | | 30 Sep |
Reference Implementation (https://github.com/jsr107/RI), Technology Compatibility Kit | | 31 Oct |
Appeal Ballot (7 days) | 31 Oct | 7 Nov |
Final Approval Ballot | 14 Nov | 28 Nov |
Final Release | 28 Nov | 12 Dec |
Source: JavaOne 2013
Concurrent Map
The following code is not thread safe
private Cache<String, Integer> cache;
public void incrementUnsafe(String user) {
if ( ! cache.containsKey(user) ) {
cache.put(user, 0);
}
int current = cache.get(user);
cache.put("user", current + 1);
}
Concurrent Map
Synchronized only works within single VM.
private Cache<String, Integer> cache;
public synchronized void incrementThreadSafe(String user) {
if ( ! cache.containsKey(user) ) {
cache.put(user, 0);
}
int current = cache.get(user);
cache.put("user", current + 1);
}
Concurrent Map
Atomic Compare and Swap
private Cache<String, Integer> cache;
public void incrementAtomic(String user) {
cache.putIfAbsent(user, 0);
int current;
do {
current = cache.get(user);
}
while (!cache.replace(user, current, current + 1));
}
Concurrent Map
CAS operations can be understood
as an optimistic locking approach.
Alternatively, caches provide
pessimistic lock / mutate / unlock.