|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
public interface EntityLock
The EntityLock is a reentrant Lock for a lockable object (not
only for entity objects). A lockable object implements ReadLockable,
WriteLockable or both.
Depending on the EntityLockAdapterFactory used, an EntityLock
can be a read lock, a write lock or both at the same time. For entities,
their file system's EntityLockAdapterFactory is used. For other
objects, this has to be provided by the creator somehow,
A lockable object is locked by calling its
ReadLockable.lockForReading() or
WriteLockable.lockForWriting() methods. A client can also get a
custom lock for an entity by calling its EntityView.lock(Object)
method.
If a locking method is called on the view of an entity, it locks the entity itself.
A client that uses EntityFS entities concurrently from several threads must
implement a locking strategy to avoid deadlocks. The entity objects
themselves do not assume any specific locking strategy; the client should be
free to choose a suitable strategy for itself. The static utility classes
like Files or Directories
, however, use the following locking strategy:
hashCode order. Entities are Comparable based on their
hashCode:s to make this easier.Always keep a reference to a locked lock or to the locked entity. If the locking thread does not, the locked entity object may be garbage collected and then the next thread wanting to use the same entity will then get a new, unlocked entity object for the same entity.
The class EntityLocks contains static utility methods for working
with locks.
Java Concurrency in Practice is an excellent book on concurrent programming in Java.
ReadLockable,
WriteLockable| Method Summary | |
|---|---|
int |
getHoldCount()
Get the hold count of the lock. |
Lockable |
getLocked()
Get the locked object. |
boolean |
isDummy()
Is this lock a dummy lock. |
boolean |
isHeldByCurrentThread()
Is this lock held by the current thread? (This is implemented by ReentrantLock but not specified in the Lock interface.) |
boolean |
isReadLock()
Returns true if this lock is a read lock. |
boolean |
isWriteLock()
Returns true if this lock is a write lock. |
| Methods inherited from interface java.util.concurrent.locks.Lock |
|---|
lock, lockInterruptibly, newCondition, tryLock, tryLock, unlock |
| Method Detail |
|---|
Lockable getLocked()
null.
null if this lock is not connected
to any particular object.boolean isReadLock()
true if this lock is a read lock.
true if this is a read lock, false if it is a
write lock.boolean isWriteLock()
true if this lock is a write lock.
true if this is a write lock, false if this is a
read lock.boolean isHeldByCurrentThread()
ReentrantLock but not specified in the Lock interface.)
true if this lock is locked by the current thread.int getHoldCount()
Lock.lock() has been
called minus the number of times Lock.unlock() has been called by
the current thread.) If the hold count is 0, the lock is unlocked. The
hold count can never be less than 0.
boolean isDummy()
true if this is a dummy lock.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||