用法
创建一个InterProcessSemaphoreMutex
public InterProcessSemaphoreMutex(CuratorFramework client,
String path)
Parameters:
client - client
path - the path to lock
一般用法
要获取锁,请使用以下方法之一:
public void acquire()
Acquire the mutex - blocking until it's available. Must be balanced by a call to release().
public boolean acquire(long time,
TimeUnit unit)
Acquire the mutex - blocks until it's available or the given time expires. Must be balanced by a call to release().
Parameters:
time - time to wait
unit - time unit
Returns:
true if the mutex was acquired, false if not
要释放互斥量,请调用:
public void release()
Perform one release of the mutex if the calling thread is the same thread that acquired it.