public class InfinispanLock extends Object
Lock is allowing to use any object as lock
owner. It is possible to use a Thread as lock owner that makes similar to Lock.
In addition, it has an asynchronous interface. acquire(Object, long, TimeUnit) will not acquire the lock
immediately (except if it is free) but will return a ExtendedLockPromise. This promise allow to test if the
lock is acquired asynchronously and cancel the lock acquisition, without any blocking.| Constructor and Description |
|---|
InfinispanLock(TimeService timeService)
Creates a new instance.
|
InfinispanLock(TimeService timeService,
Runnable releaseRunnable)
Creates a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
ExtendedLockPromise |
acquire(Object lockOwner,
long time,
TimeUnit timeUnit)
It tries to acquire this lock.
|
boolean |
containsLockOwner(Object lockOwner)
It tests if the lock has the lock owner.
|
void |
deadlockCheck(DeadlockChecker deadlockChecker)
It forces a deadlock checking.
|
Object |
getLockOwner() |
boolean |
isLocked()
It checks if the lock is acquired.
|
void |
release(Object lockOwner)
It tries to release the lock held by
lockOwner. |
void |
setTimeService(TimeService timeService)
Tests purpose only!
|
public InfinispanLock(TimeService timeService)
timeService - the TimeService to check for timeouts.public InfinispanLock(TimeService timeService, Runnable releaseRunnable)
timeService - the TimeService to check for timeouts.releaseRunnable - a Runnable that is invoked every time this lock is released.public void setTimeService(TimeService timeService)
public ExtendedLockPromise acquire(Object lockOwner, long time, TimeUnit timeUnit)
ExtendedLockPromise is returned until it has
timed-out or release(Object) is invoked.
If the lock is free, it is immediately acquired, otherwise the lock owner is queued.lockOwner - the lock owner who needs to acquire the lock.time - the timeout value.timeUnit - the timeout unit.ExtendedLockPromise.NullPointerException - if lockOwner or timeUnit is null.public void release(Object lockOwner)
lockOwner.
If the lock is not acquired (is waiting or timed out/deadlocked) by lockOwner, its ExtendedLockPromise is canceled. If lockOwner is the current lock owner, the lock is released and the
next lock owner available will acquire the lock. If the lockOwner never tried to acquire the lock, this
method does nothing.lockOwner - the lock owner who wants to release the lock.NullPointerException - if lockOwner is null.public Object getLockOwner()
null if it is not acquired.public boolean isLocked()
false return value does not mean the lock is free since it may have queued lock owners.true if the lock is acquired.public void deadlockCheck(DeadlockChecker deadlockChecker)
public boolean containsLockOwner(Object lockOwner)
true if the lock owner is the current lock owner or it in the queue.lockOwner - the lock owner to test.true if it contains the lock owner.Copyright © 2025 JBoss, a division of Red Hat. All rights reserved.