配置mongo的表进行锁任务管理
maven依赖包
<dependency><groupId>net.javacrumbs.shedlock</groupId><artifactId>shedlock-spring</artifactId><version>2.5.0</version></dependency><dependency><groupId>net.javacrumbs.shedlock</groupId><artifactId>shedlock-provider-mongo</artifactId><version>2.5.0</version></dependency>
SpringBoot配置代码
@Configuration
public class ShedLockConfig {@Autowiredprivate MongoTemplate template;@Beanpublic LockProvider lockProvider(){MongoCollection<Document> mongo = template.getCollection("shed_lock");return new MongoLockProvider(mongo);}//并发的调度任务池,默认是单线程调度@Bean(destroyMethod="shutdown")public ScheduledExecutorService shedLockTaskExecutors() {return Executors.newScheduledThreadPool(20);}
}