26 Star 141 Fork 84

SOFAStack / sofa-jraft

 / 详情

DistributedLock中getFencingToken如何使用?

待办的
创建于  
2021-10-11 17:35

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);
}

// 以上使用方法是否正确?

评论 (2)

胶布小子 创建了任务
胶布小子 关联仓库设置为SOFAStack/sofa-jraft
展开全部操作日志

应该这样用才对

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(1)
Java
1
https://gitee.com/sofastack/sofa-jraft.git
git@gitee.com:sofastack/sofa-jraft.git
sofastack
sofa-jraft
sofa-jraft

搜索帮助