更新时间:2024-11-28 GMT+08:00
ShedLock
ShedLock是一个用于分布式任务调度的开源库。
它提供了一种简单而可靠的方式来确保在分布式环境中只有一个节点执行指定的任务。
对接ShedLock命令参考如下。
import com.huawei.devspore.mas.redis.core.MultiZoneClient; import com.huawei.devspore.mas.redis.spring.boot.cache.DcsConnectionFactory; 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.scheduling.annotation.EnableScheduling; @Configuration @EnableScheduling @EnableSchedulerLock(defaultLockAtMostFor = "PT30S") public class ShedLockJdbcConfig { @Bean public DcsConnectionFactory dcsConnectionFactory(MultiZoneClient client) { return new DcsConnectionFactory(client); } @Bean public LockProvider lockProvider(DcsConnectionFactory connectionFactory) { return new RedisLockProvider(connectionFactory); } }
父主题: 客户各场景替换方案