Using the Coherence ConcurrentMap Interface (Locking API)
Posted
by jpurdy
on Oracle Blogs
See other posts from Oracle Blogs
or by jpurdy
Published on Fri, 1 Jun 2012 01:33:30 +0000
Indexed on
2012/06/01
4:45 UTC
Read the original article
Hit count: 168
/Coherence
For many developers using Coherence, the first place they look for concurrency control is the com.tangosol.util.ConcurrentMap interface (part of the NamedCache interface).
The ConcurrentMap interface includes methods for explicitly locking data. Despite the obvious appeal of a lock-based API, these methods should generally be avoided for a variety of reasons:
- They are very "chatty" in that they can't be bundled with other operations (such as get and put) and there are no collection-based versions of them.
- Locks do directly not impact mutating calls (including puts and entry processors), so all code must make explicit lock requests before modifying (or in some cases reading) cache entries.
- They require coordination of all code that may mutate the objects, including the need to lock at the same level of granularity (there is no built-in lock hierarchy and thus no concept of lock escalation).
- Even if all code is properly coordinated (or there's only one piece of code), failure during updates that may leave a collection of changes to a set of objects in a partially committed state.
- There is no concept of a read-only lock.
In general, use of locking is highly discouraged for most applications. Instead, the use of entry processors provides a far more efficient approach, at the cost of some additional complexity.
© Oracle Blogs or respective owner