forked from hugegraph/hugegraph-sync
HugeGraph-407: add KeyLock class
Change-Id: I655bdf4da20e0c6b6d7796958485ab066f0020f1
This commit is contained in:
parent
5603b9c6a3
commit
7bdf878dd4
|
|
@ -0,0 +1,26 @@
|
|||
package com.baidu.hugegraph.concurrent;
|
||||
|
||||
import java.util.concurrent.locks.Lock;
|
||||
|
||||
import com.google.common.util.concurrent.Striped;
|
||||
|
||||
public class KeyLock {
|
||||
|
||||
private Striped<Lock> locks;
|
||||
|
||||
public KeyLock() {
|
||||
this(Runtime.getRuntime().availableProcessors() * 4);
|
||||
}
|
||||
|
||||
public KeyLock(int size) {
|
||||
this.locks = Striped.lock(size);
|
||||
}
|
||||
|
||||
public final void lock(Object key) {
|
||||
this.locks.get(key).lock();
|
||||
}
|
||||
|
||||
public final void unlock(Object key) {
|
||||
this.locks.get(key).unlock();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue