Class StampedLockExecutor

  • All Implemented Interfaces:
    LockExecutor

    public class StampedLockExecutor
    extends Object
    implements LockExecutor
    基于StampedLock锁执行器(不可重入)
    Author:
    Pan
    • Constructor Detail

      • StampedLockExecutor

        public StampedLockExecutor()
        构造函数
      • StampedLockExecutor

        public StampedLockExecutor​(StampedLock stampedLock)
        自定义锁
        Parameters:
        stampedLock - 不可重入锁
    • Method Detail

      • lock

        public void lock​(Runnable action)
        Description copied from interface: LockExecutor
        执行带锁的操作(使用默认锁,对于读写锁而言是写锁)
        Specified by:
        lock in interface LockExecutor
        Parameters:
        action - 范围内进行锁操作
      • lock

        public <V> V lock​(Supplier<V> action)
        Description copied from interface: LockExecutor
        执行带锁的操作并返回结果(使用默认锁,对于读写锁而言是写锁)
        Specified by:
        lock in interface LockExecutor
        Type Parameters:
        V - 返回值类型
        Parameters:
        action - 范围内进行锁操作
        Returns:
        V 执行结果
      • readLock

        public void readLock​(Runnable action)
        Description copied from interface: LockExecutor
        读写锁特有方法,默认抛出 UnsupportedOperationException
        Specified by:
        readLock in interface LockExecutor
        Parameters:
        action - 范围内进行锁操作
      • readLock

        public <V> V readLock​(Supplier<V> action)
        Description copied from interface: LockExecutor
        读写锁特有方法,默认抛出 UnsupportedOperationException
        可自定义返回值
        避免在循环中使用拉姆达表达式在用此锁会降低效率
        Specified by:
        readLock in interface LockExecutor
        Type Parameters:
        V - 返回值类型
        Parameters:
        action - 范围内进行锁操作
        Returns:
        V 执行结果
      • writeLock

        public void writeLock​(Runnable action)
        Description copied from interface: LockExecutor
        读写锁特有方法,默认抛出 UnsupportedOperationException
        Specified by:
        writeLock in interface LockExecutor
        Parameters:
        action - 范围内进行锁操作
      • writeLock

        public <V> V writeLock​(Supplier<V> action)
        Description copied from interface: LockExecutor
        读写锁特有方法,默认抛出 UnsupportedOperationException
        Specified by:
        writeLock in interface LockExecutor
        Type Parameters:
        V - 返回值类型
        Parameters:
        action - 范围内进行锁操作
        Returns:
        V 执行结果
      • getLock

        public Lock getLock()
        Description copied from interface: LockExecutor
        获取底层锁对象
        Specified by:
        getLock in interface LockExecutor
        Returns:
        Lock 锁对象
      • getReadLock

        public Lock getReadLock()
        获取读锁
        Returns:
        Lock
      • getWriteLock

        public Lock getWriteLock()
        获取写锁
        Returns:
        Lock
      • getStampedLock

        public StampedLock getStampedLock()
        获取不可重入锁
        Returns:
        StampedLock