I have a custom ThreadPoolTaskScheduler which I want to use in LockableTaskScheduler instance I defined in the config as below:
@Configuration
public class ApplicationConfiguration {
@Autowired DataSource dataSource;
@Bean
public LockProvider lockProvider() {
return new JdbcTemplateLockProvider(
JdbcTemplateLockProvider.Configuration.builder()
.withJdbcTemplate(new JdbcTemplate(dataSource))
.usingDbTime()
.build()
);
}
@Bean
public TaskScheduler lockableTaskScheduler(){
ThreadPoolTaskScheduler threadPoolTaskScheduler = new
ThreadPoolTaskScheduler();
threadPoolTaskScheduler.setPoolSize(2);
threadPoolTaskScheduler.initialize();
return new LockableTaskScheduler(threadPoolTaskScheduler, lockManager());
}
@Bean
public LockManager lockManager(){
return new DefaultLockManager(lockProvider(), lockConfigurationExtractor());
}
@Bean /*** PROBLEM HERE ***/
public LockConfigurationExtractor lockConfigurationExtractor(){
return new SpringLockConfigurationExtractor();
}
}
And I instantiate dynamic schedules programatically as below:
@Autowired
TaskScheduler lockableTaskScheduler;
...
CronTrigger cronTrigger = new CronTrigger(cronExpression, TimeZone.getTimeZone(TimeZone.getDefault().getID()));
Runnable runnable = () -> someMethod();
ScheduledFuture<?> scheduledTask = lockableTaskScheduler.schedule(runnable, cronTrigger);
But I couldn't find any public implementation of LockConfigurationExtractor
to create a LockConfigurationExtractor
bean.
P.S. I went through the source code and the test cases. But LockConfigurationExtractor
does not seem to have a public concrete implementation accessible outside the library package.
Is there any other way to define/get the DefaultLockManager
bean?
Edit:
Actually my main goal is not to create the LockableTaskScheduler at all. I just want to schedule a "Lockable" runnable somehow as:
ScheduledFuture<?> scheduledTask = lockableTaskScheduler.schedule(<lockable_runnable>, cronTrigger);
So that when the runnable is fired it can not run simultaneously in another node. (note: The dynamic/programmatic scheduling part of the business logic is not avoidable ATM)