Class LockingGate


  • public class LockingGate
    extends java.lang.Object
    A gate that allow easy awaiting and locking in multithread tests.
    • Constructor Detail

      • LockingGate

        public LockingGate()
    • Method Detail

      • getUnlockingThread

        public java.lang.Thread getUnlockingThread()
        Gets a thread that is expected to call unlock() method
        Returns:
        thread to unlock gate
      • getLockingThread

        public java.lang.Thread getLockingThread()
        Gets a thread that is expected to call lock() method
        Returns:
        thread to lock gate
      • registerLockingThread

        public void registerLockingThread()
        Marks current thread as the one to call lock() method
      • registerUnlockingThread

        public void registerUnlockingThread()
        Marks current thread as the one to call unlock() method
      • assureLocked

        public void assureLocked()
        Awaits until gate is locked - some thread calls lock() method. Method returns immediately, if gate is already locked. Current thread is considered as the one to call unlock() method.
        See Also:
        registerUnlockingThread()
      • lock

        public void lock()
        Locks this gate. If unlocker is already waiting for gate to be locked (see assureLocked()), it is released. Method return immediately, if gate was already unlocked (see unlock()) by other thread - otherwise current thread awaits until gate gets unlocked.
        See Also:
        registerLockingThread()
      • assureInLockingThread

        protected void assureInLockingThread()
      • assureUnlockingThreadRegistered

        protected java.lang.Thread assureUnlockingThreadRegistered()
      • unlock

        public void unlock()
        Unlocks this gate. If a locking thread is already waiting for gate to be unlocked (see lock()), it is released.
      • assureInUnlockingThread

        protected void assureInUnlockingThread()
      • assureLockingThreadRegistered

        protected java.lang.Thread assureLockingThreadRegistered()