File tree Expand file tree Collapse file tree
src/main/java/org/springframework/lock/aspect Expand file tree Collapse file tree Original file line number Diff line number Diff line change 6161<tr >
6262<td >0.4.0.0</td ><td >完成乐观锁开发。目前有互斥锁、读写锁、乐观锁,均已测试可用</td ><td >2022年1月30日</td >
6363</tr >
64+ <tr >
65+ <td >0.5.0.0</td ><td >优化执行逻辑,提升互斥锁性能</td ><td >2021年1月31日</td >
66+ </tr >
6467</table >
Original file line number Diff line number Diff line change @@ -31,34 +31,24 @@ public class SynchronizedAspect {
3131 @ Around (value = "@annotation(org.springframework.lock.annotation.Synchronized)" )
3232 public Object aroundSynchronized (ProceedingJoinPoint jp ) throws Throwable {
3333 Class <?> clz = jp .getTarget ().getClass ();
34- Object lock = null ;
34+ Object lock = clz ;
3535 MethodSignature signature = (MethodSignature ) jp .getSignature ();
3636 Method method = signature .getMethod ();
37- boolean foundField = false ;
38- if (method == null )
39- lock = clz ;
40- else {
37+ if (method != null ) {
4138 Synchronized annotation = method .getAnnotation (Synchronized .class );
42- if (annotation == null )
43- lock = clz ;
44- else {
39+ if (annotation != null ){
4540 String varName = annotation .value ();
46- if ("" .equals (varName ))
47- lock = clz ;
48- else {
41+ if (!"" .equals (varName )) {
4942 for (Field field : clz .getDeclaredFields ()) {
5043 field .setAccessible (true );
5144 if (varName .equals (field .getName ())){
52- foundField = true ;
5345 lock = field .get (jp .getTarget ());
5446 break ;
5547 }
5648 }
5749 }
5850 }
5951 }
60- if (!foundField )
61- lock = clz ;
6252 Object result = null ;
6353 synchronized (lock ) {
6454 LOGGER .info (clz .getSimpleName () + "获得互斥锁" );
You can’t perform that action at this time.
0 commit comments