Class StampedLockExecutor
- java.lang.Object
-
- com.gitee.apanlh.util.thread.lock.StampedLockExecutor
-
- All Implemented Interfaces:
LockExecutor
public class StampedLockExecutor extends Object implements LockExecutor
基于StampedLock锁执行器(不可重入)- Author:
- Pan
-
-
Constructor Summary
Constructors Constructor Description StampedLockExecutor()构造函数StampedLockExecutor(StampedLock stampedLock)自定义锁
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description LockgetLock()获取底层锁对象LockgetReadLock()获取读锁StampedLockgetStampedLock()获取不可重入锁LockgetWriteLock()获取写锁voidlock(Runnable action)执行带锁的操作(使用默认锁,对于读写锁而言是写锁)<V> Vlock(Supplier<V> action)执行带锁的操作并返回结果(使用默认锁,对于读写锁而言是写锁)voidreadLock(Runnable action)读写锁特有方法,默认抛出 UnsupportedOperationException<V> VreadLock(Supplier<V> action)读写锁特有方法,默认抛出 UnsupportedOperationException
可自定义返回值
避免在循环中使用拉姆达表达式在用此锁会降低效率voidwriteLock(Runnable action)读写锁特有方法,默认抛出 UnsupportedOperationException<V> VwriteLock(Supplier<V> action)读写锁特有方法,默认抛出 UnsupportedOperationException
-
-
-
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:
lockin interfaceLockExecutor- Parameters:
action- 范围内进行锁操作
-
lock
public <V> V lock(Supplier<V> action)
Description copied from interface:LockExecutor执行带锁的操作并返回结果(使用默认锁,对于读写锁而言是写锁)- Specified by:
lockin interfaceLockExecutor- Type Parameters:
V- 返回值类型- Parameters:
action- 范围内进行锁操作- Returns:
- V 执行结果
-
readLock
public void readLock(Runnable action)
Description copied from interface:LockExecutor读写锁特有方法,默认抛出 UnsupportedOperationException- Specified by:
readLockin interfaceLockExecutor- Parameters:
action- 范围内进行锁操作
-
readLock
public <V> V readLock(Supplier<V> action)
Description copied from interface:LockExecutor读写锁特有方法,默认抛出 UnsupportedOperationException
可自定义返回值
避免在循环中使用拉姆达表达式在用此锁会降低效率- Specified by:
readLockin interfaceLockExecutor- Type Parameters:
V- 返回值类型- Parameters:
action- 范围内进行锁操作- Returns:
- V 执行结果
-
writeLock
public void writeLock(Runnable action)
Description copied from interface:LockExecutor读写锁特有方法,默认抛出 UnsupportedOperationException- Specified by:
writeLockin interfaceLockExecutor- Parameters:
action- 范围内进行锁操作
-
writeLock
public <V> V writeLock(Supplier<V> action)
Description copied from interface:LockExecutor读写锁特有方法,默认抛出 UnsupportedOperationException- Specified by:
writeLockin interfaceLockExecutor- Type Parameters:
V- 返回值类型- Parameters:
action- 范围内进行锁操作- Returns:
- V 执行结果
-
getLock
public Lock getLock()
Description copied from interface:LockExecutor获取底层锁对象- Specified by:
getLockin interfaceLockExecutor- Returns:
- Lock 锁对象
-
getReadLock
public Lock getReadLock()
获取读锁- Returns:
- Lock
-
getWriteLock
public Lock getWriteLock()
获取写锁- Returns:
- Lock
-
getStampedLock
public StampedLock getStampedLock()
获取不可重入锁- Returns:
- StampedLock
-
-