Class AtomicLock

  • All Implemented Interfaces:
    java.util.concurrent.locks.Lock
    Direct Known Subclasses:
    FinalAtomicLock

    public class AtomicLock
    extends java.lang.Object
    implements java.util.concurrent.locks.Lock
    The implementation of the Lock based on using AtomicInteger without supporting reentrant calls.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int sink
      The field for consuming CPU.
      protected java.util.concurrent.atomic.AtomicInteger status
      The status of lock.
    • Constructor Summary

      Constructors 
      Constructor Description
      AtomicLock()
      Instantiates a new Atomic lock.
    • Field Detail

      • status

        protected final java.util.concurrent.atomic.AtomicInteger status
        The status of lock.
      • sink

        protected int sink
        The field for consuming CPU.
    • Constructor Detail

      • AtomicLock

        public AtomicLock()
        Instantiates a new Atomic lock.
    • Method Detail

      • lock

        public void lock()
        Specified by:
        lock in interface java.util.concurrent.locks.Lock
      • consumeCPU

        protected void consumeCPU()
        Consume cpu.
      • lockInterruptibly

        public void lockInterruptibly()
                               throws java.lang.InterruptedException
        Specified by:
        lockInterruptibly in interface java.util.concurrent.locks.Lock
        Throws:
        java.lang.InterruptedException
      • newCondition

        public java.util.concurrent.locks.Condition newCondition()
        Specified by:
        newCondition in interface java.util.concurrent.locks.Lock
      • tryLock

        public boolean tryLock()
        Specified by:
        tryLock in interface java.util.concurrent.locks.Lock
      • tryLock

        public boolean tryLock​(long time,
                               java.util.concurrent.TimeUnit unit)
                        throws java.lang.InterruptedException
        Specified by:
        tryLock in interface java.util.concurrent.locks.Lock
        Throws:
        java.lang.InterruptedException
      • unlock

        public void unlock()
        Specified by:
        unlock in interface java.util.concurrent.locks.Lock
      • toString

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