![JAR search and dependency download from the Maven repository](/logo.png)
net.sf.ehcache.constructs.locking.package.html Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ehcache-explicitlocking Show documentation
Show all versions of ehcache-explicitlocking Show documentation
Ehcache module that allows explicit locking
The newest version!
This package contains an implementation of an Ehcache which provides for explicit locking,
using READ and WRITE locks.
It is possible to get more control over Ehcache's locking behaviour.
Standalone Ehcache
In standalone ehcache core, there is no locking. The last write wins. This is akin to
the READ_UNCOMMITTED isolation level.
Ehcache clustered with Terracotta
In this case the cache is always coherent, akin to READ_COMMITTED isolation level. This
package simply gives you more control over when locks are acquired and released. In regular
Ehcache if you get an object to read or write it can be changed underneath you while you are
performing your application level operations on the object.
With this module you can first get the lock
for the key, then perform your app level operations preventing anyone else from writing to the
object. When the app level operations are completed you put the Element back in the cache and
release the lock so that others can now access it.
How it works
A READ lock does not prevent other READers from also acquiring a READ lock and reading. A
READ lock cannot be obtained if there is an oustanding WRITE lock - it will queue.
A WRITE lock cannot be obtained while there are outstanding READ locks - it will queue.
In each case to avoid locking problems, the lock should be released after use. The lock
release should be in a finally
block.
If before each read, you acquire a READ lock and then before each write you acquire a WRITE
lock, then an isolation level akin to READ_COMMITTED is achieved.
© 2015 - 2025 Weber Informatics LLC | Privacy Policy