如何理解何时获得并释放了锁锁?

时间:2019-03-31 09:07:08

标签: java spring-boot locking distributed-system shedlock

我有这样的代码:

private final ThreadPoolTaskScheduler threadPoolTaskScheduler; // spring
private final LockingTaskExecutor lockingTaskExecutor; // shedlock
....
    threadPoolTaskScheduler.scheduleWithFixedDelay(
                    () -> {
                        lockConfiguration = ...
                        long start = System.currentTimeMillis();
                        LOGGER.info("Spring scheduler started task, awaiting shedlock ");
                        lockingTaskExecutor.executeWithLock((Runnable) () -> {
                                    LOGGER.info("Shedlock acquired. duration=[{}]ms", propertyItem, System.currentTimeMillis() - start);
                                taks();
                                },
                                lockConfiguration);
                    }, someInterval);

我有2个节点。根据日志,我看到task()仅在第一个节点上起作用的情况。在第二个节点上,我仅看到Spring scheduler started task, awaiting shedlock

我认为它不应该以这种方式起作用,我想调查它发生的原因。

释放锁后如何订阅事件?

锁尝试获取锁多长时间?

P.S。

someInterval = 30分钟

lockConfiguration:至少= 5分钟,在atMost = 20分钟

1 个答案:

答案 0 :(得分:0)

我研究了源代码,发现shedlock尝试获取锁,如果锁繁忙,它只会跳过任务

相关问题