Package jade.util

Class RWLock

  • Direct Known Subclasses:
    SynchList

    public class RWLock
    extends Object
    This class provides support for synchronizing threads acting on a generic resource in such a way that - If a thread is writing the resource no other thread can act on it in any way - Several threads can read the resource at the same time - If one or more threads are reading the resource no thread can write it
    Author:
    Giovanni Caire - TILab
    • Constructor Summary

      Constructors 
      Constructor Description
      RWLock()
      Default constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void onWriteEnd()
      This placeholder method is called every time a thread actually releases the protected resource with writing privileges (this means that, in case of multiple recursive unlocking by the same thread, this method is called only the last time).
      protected void onWriteStart()
      This placeholder method is called every time a thread actually acquires the protected resource with writing privileges (this means that, in case of multiple recursive locking by the same thread, this method is called only the first time).
      void readLock()
      Acquire the protected resource with reading privileges.
      void readUnlock()
      Release the protected resource, previously acquired with reading privileges.
      void writeLock()
      Acquire the protected resource with writing privileges.
      void writeUnlock()
      Release the protected resource, previously acquired with writing privileges.
    • Constructor Detail

      • RWLock

        public RWLock()
        Default constructor.
    • Method Detail

      • writeLock

        public void writeLock()
        Acquire the protected resource with writing privileges. Only one writer at a time can access the protected resource, and no readers can access it at the same time. The locking is recursive (i.e. the same thread can acquire the lock multiple times, but must unlock it a matching number of times to actually free the protected resource).
      • writeUnlock

        public void writeUnlock()
        Release the protected resource, previously acquired with writing privileges.
      • readLock

        public void readLock()
        Acquire the protected resource with reading privileges. Many readers can access the protected resource at the same time, but no writer can access it while at least one reader is present. The locking is recursive (i.e. the same thread can acquire the lock multiple times, but must unlock it a matching number of times to actually free the protected resource).
      • readUnlock

        public void readUnlock()
        Release the protected resource, previously acquired with reading privileges.
      • onWriteStart

        protected void onWriteStart()
        This placeholder method is called every time a thread actually acquires the protected resource with writing privileges (this means that, in case of multiple recursive locking by the same thread, this method is called only the first time). Subclasses can exploit this to transparently trigger a resource acquisition prolog.
      • onWriteEnd

        protected void onWriteEnd()
        This placeholder method is called every time a thread actually releases the protected resource with writing privileges (this means that, in case of multiple recursive unlocking by the same thread, this method is called only the last time). Subclasses can exploit this to transparently trigger a resource release epilog.