Class Semaphore

  • All Implemented Interfaces:
    Sync
    Direct Known Subclasses:
    WaitSemaphore

    public class Semaphore
    extends java.lang.Object
    implements Sync
    Semaphore that can allow a specified number of threads to enter, blocking the others. If the specified number of threads is 1, it acts as an exclusive semaphore and can be used instead of synchronized blocks
    Version:
    $Revision$
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private class  Semaphore.Info  
    • Constructor Summary

      Constructors 
      Constructor Description
      Semaphore​(int allowed)  
    • Field Detail

      • m_users

        private int m_users
      • m_allowed

        private int m_allowed
      • m_logMap

        private java.util.Map m_logMap
    • Constructor Detail

      • Semaphore

        public Semaphore​(int allowed)
    • Method Detail

      • getUsers

        public int getUsers()
      • acquire

        public void acquire()
                     throws java.lang.InterruptedException
        Description copied from interface: Sync
        Acquires this sync
        Specified by:
        acquire in interface Sync
        Throws:
        java.lang.InterruptedException
        See Also:
        Sync.release()
      • release

        public void release()
        Description copied from interface: Sync
        Releases this sync
        Specified by:
        release in interface Sync
        See Also:
        Sync.acquire()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • waitImpl

        protected boolean waitImpl​(java.lang.Object lock)
                            throws java.lang.InterruptedException
        Throws:
        java.lang.InterruptedException
      • logAcquire

        protected void logAcquire()
      • logDeadlock

        protected void logDeadlock()
      • logRelease

        protected void logRelease()