Class ReadWriteSynchronizer
- java.lang.Object
-
- org.apache.commons.configuration2.sync.ReadWriteSynchronizer
-
- All Implemented Interfaces:
Synchronizer
public class ReadWriteSynchronizer extends Object implements Synchronizer
A special implementation of
Synchronizerbased on the JDK'sReentrantReadWriteLockclass.This class manages a
ReadWriteLockobject internally. The methods of theSynchronizerinterface are delegated to this lock. So this class behaves in the same way as documented forReentrantReadWriteLock.Using this
Synchronizerimplementation is appropriate to make configuration objects thread-safe. This means that multiple threads can read configuration data in parallel; if one thread wants to update the configuration, this happens with an exclusive lock.- Since:
- 2.0
-
-
Constructor Summary
Constructors Constructor Description ReadWriteSynchronizer()Creates a new instance ofReadWriteSynchronizerand initializes it with a lock object of typeReentrantReadWriteLock.ReadWriteSynchronizer(ReadWriteLock l)Creates a new instance ofReadWriteSynchronizerand initializes it with the given lock object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbeginRead()Notifies thisSynchronizerthat the current thread is going to start a read operation on the managed configuration.voidbeginWrite()Notifies thisSynchronizerthat the current thread is going to start a write operation on the managed configuration.voidendRead()Notifies thisSynchronizerthat the current thread has finished its read operation.voidendWrite()Notifies thisSynchronizerthat the current thread has finished its write operation.
-
-
-
Constructor Detail
-
ReadWriteSynchronizer
public ReadWriteSynchronizer(ReadWriteLock l)
Creates a new instance ofReadWriteSynchronizerand initializes it with the given lock object. This constructor can be used to pass a lock object which has been configured externally. If the lock object is null, a default lock object is created.- Parameters:
l- the lock object to be used (can be null)
-
ReadWriteSynchronizer
public ReadWriteSynchronizer()
Creates a new instance ofReadWriteSynchronizerand initializes it with a lock object of typeReentrantReadWriteLock.
-
-
Method Detail
-
beginRead
public void beginRead()
Description copied from interface:SynchronizerNotifies thisSynchronizerthat the current thread is going to start a read operation on the managed configuration. This call can block if a concrete implementation decides that the thread has to wait until a specific condition is fulfilled.- Specified by:
beginReadin interfaceSynchronizer
-
endRead
public void endRead()
Description copied from interface:SynchronizerNotifies thisSynchronizerthat the current thread has finished its read operation. This may cause other waiting threads to be granted access to the managed configuration.- Specified by:
endReadin interfaceSynchronizer
-
beginWrite
public void beginWrite()
Description copied from interface:SynchronizerNotifies thisSynchronizerthat the current thread is going to start a write operation on the managed configuration. This call may block. For instance, a concrete implementation may suspend the thread until all read operations currently active are finished,- Specified by:
beginWritein interfaceSynchronizer
-
endWrite
public void endWrite()
Description copied from interface:SynchronizerNotifies thisSynchronizerthat the current thread has finished its write operation. This may cause other waiting threads to be granted access to the managed configuration.- Specified by:
endWritein interfaceSynchronizer
-
-