Class StripedLock
java.lang.Object
com.sure.tool.thread.StripedLock
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
DEFAULT_STRIPES
public static final int DEFAULT_STRIPES默认段数。- See Also:
-
-
Constructor Details
-
StripedLock
public StripedLock()构造默认 16 段分段锁。 -
StripedLock
public StripedLock(int stripes) 构造指定段数分段锁(段数向上取整为 2 的幂)。- Parameters:
stripes- 段数,必须大于 0- Throws:
IllegalArgumentException- stripes 不大于 0
-
-
Method Details
-
get
按 key 获取对应段锁。相同 key 恒返回同一把锁。- Parameters:
key- 锁键,null视为常量 0- Returns:
- 段锁
-
get
-
lockCount
public int lockCount()返回段锁总数。- Returns:
- 段数
-
runLocked
-
runLocked
-