ReadAccessSemaphore

class ReadAccessSemaphore extends Semaphore implements Releasable

Acquire and release read access. DatabaseAccessManager uses this class for managing access to the back-end during processing updates, inserts, deletions and retrievals. Read access will be granted immediately for every thread that requests it, unless a thread requests that read access be blocked (usually by requesting write access). If this happens, all threads that already have read access will proceed and release their read access as usual but no NEW read permits will be granted.

This is a blockable Semaphore. Any number of threads may acquire a permit unless it is blocked. The blocking thread (requesting a WriteAccessLock) waits until all threads have released their permits.

Author:

Timm Fitschen

Fields

writersBlock

Semaphore writersBlock

Constructors

ReadAccessSemaphore

public ReadAccessSemaphore()

Methods

acquire

public void acquire()

Acquire a read access permit if and only if it has not been blocked via block(). If read access is currently blocked, the thread waits until the unblock() method is invoked by any thread.

block

public void block()

Acquire the permit to block further read access, if no thread currently has acquired read access and no thread currently has a block.

Consequences of calling this method are:

  • Further read access permits are blocked for any thread.

  • Every thread that has a read access already can proceed. The current thread waits until all threads have released their read access.

If another thread has invoked this method before, the current thread waits until the unblock() method is called.

Throws:

release

public void release()

Release a read access permit.

If this is the last remaining acquired permit, also release the general writersBlock.

unblock

public void unblock()

Unblock read access.

This method releases the writersBlock introduced by calling the block() method.

waitingAquireAccess

public int waitingAquireAccess()