'Spring boot shedlock runs two tasks on several instances

We started using ShedLock and need to run two tasks once a day. Therefore, I defined two tasks with different lock names in one class (so that they could run simultaneously). Execution start time I set the same for booth jobs. But for some reason, the tasks were executed on two instances (we have 3 instances in total). On tst it works well (Maybe because the data set is smaller). I am trying to understand why.

Here my class:

@Service
public class ProcessDataScheduledService {

private final MyService myService;

@Scheduled(cron = "0 0 1 * * *")
@SchedulerLock(name = "task1"
            lockAtLeastFor = "PT1H",
            lockAtMostFor = "PT1H")
public void processData1() {
        myService.doSomething_1();
    }

@Scheduled(cron = "0 0 1 * * *")
@SchedulerLock(name = "task2",
            lockAtLeastFor = "PT1H",
            lockAtMostFor = "PT1H")
public void processData2() {
        myService.doSomething_2();
    }
}

LockProvider:

public LockProvider lockProvider(@Qualifier("pgsqlDataSource") DataSource dataSource) {
        return new JdbcTemplateLockProvider(JdbcTemplateLockProvider.Configuration.builder()
                .withJdbcTemplate(new JdbcTemplate(dataSource))
                .usingDbTime()
                .build());
}

Here is information about the start and end of tasks:

task1    host = server_1,  time execution: 01:00:00.313 --- 02:02:54.695
task2    host = server_1,  time execution: 02:02:54.709 --- 05:25:02.066

task2    host = server_2,  time execution: 01:00:00.321 --- 04:21:13.377
task1    host = central_2,  time execution: 04:21:13.398 --- 05:19:08.828


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source