- bropen.toolkit.utils.concurrent.ShareLock
-
共享锁
通过字符串作为锁钥,获得锁对象后,借助 synchronized 加锁;不支持跨应用、集群。
示例:
String key = ShareLock.createKey(userId, "xxxx", "yyyy")
synchronized (ShareLock.lock(key)) {
// DO STH.
}
- Since:
- 4.8.1
-
-
Methods Summary
Methods
| Type |
Name and description |
static String |
createKey(java.io.Serializable... keys) 拼接一个锁钥 |
static String |
lock(String key) 获得用于同步(synchronized)的锁对象 |
-
Inherited Methods Summary
Inherited Methods
| Methods inherited from class |
Name |
class Object |
Object#wait(long, int), Object#wait(long), Object#wait(), Object#equals(Object), Object#toString(), Object#hashCode(), Object#getClass(), Object#notify(), Object#notifyAll() |
-
-
Method Detail
-
public static String createKey(java.io.Serializable... keys)
拼接一个锁钥
- Returns:
- 等于
keys*.toString().join("_") 的字符串。
- Parameters:
keys - 用来拼接锁钥的多个值,不建议太长
-
public static String lock(String key)
获得用于同步(synchronized)的锁对象
- Returns:
- 用于 synchronized 的共享锁对象
- Parameters:
key - 锁钥
- Summary:
- Nested
- Field
- Constructor
- Method
- | Detail:
- Field
- Constructor
- Method
BROPEN Documentation, 2020-04-21 10:53