0

I have code like this:

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

I have 2 nodes. According logs I see situation that task() works only on first node. On second node I see only Spring scheduler started task, awaiting shedlock

I believe it should not work in a such way and I want to investigate why it happens.

How can I subscribe on event when lock is released?

How long shedlock tries to acquire lock?

P.S.

someInterval = 30 minutes

lockConfiguration: atleast = 5 min, atMost=20min

gstackoverflow
  • 36,709
  • 117
  • 359
  • 710

1 Answers1

0

I investigated source code and found out that shedlock tries to acquire lock and if lock busy it just skips the task

gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
  • 1
    It's written in the very first paragraph of ShedLock readme (in bold) – Lukas Oct 19 '19 at 06:35
  • @Lukas so you are agree – gstackoverflow Oct 19 '19 at 07:39
  • @Lukas will shedlock work if my servers run in different timezones? I see in the database that locked_intil and locked_at are stoed in my timezone – gstackoverflow Jan 16 '20 at 11:03
  • For JDBC provider you can specify timezone https://github.com/lukas-krecan/ShedLock/blob/master/providers/jdbc/shedlock-provider-jdbc-template/src/main/java/net/javacrumbs/shedlock/provider/jdbctemplate/JdbcTemplateLockProvider.java#L89 – Lukas Jan 17 '20 at 09:05
  • @Lukas Will it work for if I specify UTC on each node ? – gstackoverflow Jan 17 '20 at 09:06
  • @Lukas Based on my experiments it works too. I just wanted to know about pitfalls from author. Anyway - the requirement that the same timezone constant should be used on each node. So by default it won't work if my nodes located in a different timezones. I suppose you could use UTC by default to make library more solid. What do you think ? – gstackoverflow Jan 17 '20 at 11:37