

背景
@SchedulerLock源码分析思路总结:
一个中心(围绕@EnableDiscoveryClient开展)、两个基本点(两个方法级别的注解:@SchedulerLock和@Scheduled)。
我们都知道@SchedulerLock有两种分布式锁的方案:一个是Mysql,一个是Redis,分布式锁的底层原理不难:
-
如果是采用Mysql,则通过磁盘记录的一张表,用于存储分布式锁信息
-
如果是采用Redis,则通过内存记录的KV值,用于存储分布式锁信息
源码分析:@EnableSchedulerLock
@EnableSchedulerLock:修饰启动类
@EnableFeignClients
@SpringBootApplication
@EnableDiscoveryClient
@EnableScheduling
@EnableSchedulerLock(defaultLockAtLeastFor = "10s", defaultLockAtMostFor = "60s")
public class AuditServerApplication {
public static void main(String[] args) {
CodeSpringApplication.run(AuditServerApplication.class, args);
}
}
@Import导入资源加载类
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Import(SchedulerLockConfigurationSelector.class)
public @interface EnableSchedulerLock {
InterceptMode interceptMode() default InterceptMode.PROXY_METHOD;
String defaultLockAtMostFor();
String defaultLockAtLeastFor() default "PT0S";
AdviceMode mode() default AdviceMode.PROXY;
boolean proxyTargetClass() default false;
int order() default Ordered.LOWEST_PRECEDENCE;
}
代码分析:
-
@Import注解(将某个类

最低0.47元/天 解锁文章
2271

被折叠的 条评论
为什么被折叠?



