DistributedLock.java
1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.brframework.commondistributed.annotation;
import com.brframework.commondistributed.core.DistributedExpressionRootObject;
import com.brframework.commondistributed.exception.LockedException;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* 分布式锁
* @Author xu
* @Date 2019年9月4日22:37:26
*/
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface DistributedLock {
/**
* lock key
* 示例:
* "targetClassName + methodName + #phone"
* "targetClassName + methodName + 'simple'"
* "targetClassName + methodName + args[0]"
* 使用spring el表达式,
* 内置对象包括:
* @see DistributedExpressionRootObject
* method -> 当前method对象
* methodName -> method.getName()
* args -> 当前方法的参数,可以通过args[index]访问
* target -> 当前调用对象
* targetClassName -> target.getClass().getName()
*
*/
String key();
/**
* 锁被占用,是否等待解锁
*
* 不等待解锁时,如果出现锁被占用,将抛出锁占用异常
* @see LockedException
*/
boolean waitFor() default true;
/**
* waitFor为false,并且出现锁被占用,是否抛出LockedException异常
* 应用:
* 分布式定时任务,锁占用的时候不执行即可,不需要抛出异常
*/
boolean throwException() default true;
}