27 lines
872 B
Java
27 lines
872 B
Java
|
|
package com.zhgd.config;
|
||
|
|
|
||
|
|
import net.javacrumbs.shedlock.core.LockProvider;
|
||
|
|
import net.javacrumbs.shedlock.provider.redis.spring.RedisLockProvider;
|
||
|
|
import net.javacrumbs.shedlock.spring.annotation.EnableSchedulerLock;
|
||
|
|
import org.springframework.context.annotation.Bean;
|
||
|
|
import org.springframework.context.annotation.Configuration;
|
||
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @program: wisdomSite
|
||
|
|
* @description: 分布式定时任务锁
|
||
|
|
* @author: Mr.Peng
|
||
|
|
* @create: 2021-09-29 17:41
|
||
|
|
**/
|
||
|
|
@Configuration
|
||
|
|
// 开启定时任务锁,默认设置锁最大占用时间为60s,具体任务可覆盖此配置
|
||
|
|
@EnableSchedulerLock(defaultLockAtMostFor = "PT60S")
|
||
|
|
public class ShedLockConfig {
|
||
|
|
|
||
|
|
@Bean
|
||
|
|
public LockProvider lockProvider(RedisTemplate redisTemplate) {
|
||
|
|
return new RedisLockProvider(redisTemplate.getConnectionFactory());
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|