WriteAccessLock

class WriteAccessLock extends ReentrantLock implements Releasable

Acquire and release write access. DatabaseAccessManager uses this class for managing access to entities while processing updates, inserts, deletions and retrievals. Write access will be granted to one and only one thread if no other thread already holds read or write access permits. The write access seat has to be reserved before acquiring the lock.

The flow is as follows:

                                       No new read
                                     access possible,
   Read access      Read access    wait for running read
     possible        possible       threads to fininish

     +------+       +----------+       +----------+
+--> |  no  | ----> | reserved | ----> | acquired | --+
|    | Lock |       +----------+       +----------+   |
|    +------+                          /            |
|                           (1 seat together)         |
+-----------------------------------------------------+
            release()
Author:

Timm Fitschen

Constructors

WriteAccessLock

public WriteAccessLock(ReadAccessSemaphore readSem)

Methods

lockInterruptibly

public void lockInterruptibly()

Lock the write access seat. This method returns once all current read permits have been released.

release

public void release()

reserve

public void reserve()

Reserve the seat for the next write access. While a write access is reserved but not yet acquired, all read access may still be granted. When a write access has been already granted or another reservation is active, the thread waits until the write access has been released.

Throws:

unlock

public void unlock()

whoHasReservedAccess

public Thread whoHasReservedAccess()