public static void lockAndAutoKeepLease(final RheaKVStore rheaKVStore) {
final ScheduledExecutorService watchdog = Executors.newSingleThreadScheduledExecutor();
final String lockKey = "lock_example1";
final DistributedLock<byte[]> lock = rheaKVStore.getDistributedLock(lockKey, 3, TimeUnit.SECONDS, watchdog);
long old = lock.getFencingToken();
if (lock.tryLock()) {
try {
long current = lock.getFencingToken();
if (old == current) {
LOG.info("Lock success with: {}", lockKey);
} else {
// error
}
} finally {
lock.unlock();
}
} else {
LOG.info("Fail to lock with: {}", lockKey);
}
ExecutorServiceHelper.shutdownAndAwaitTermination(watchdog);
}
// 以上使用方法是否正确?