Skip to content

Commit

Permalink
version 0.5.0.0 update
Browse files Browse the repository at this point in the history
优化执行逻辑,提升互斥锁性能
  • Loading branch information
ZongXR committed Jan 31, 2022
1 parent ae0a1c2 commit ba558ca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,7 @@
<tr>
<td>0.4.0.0</td><td>完成乐观锁开发。目前有互斥锁、读写锁、乐观锁,均已测试可用</td><td>2022年1月30日</td>
</tr>
<tr>
<td>0.5.0.0</td><td>优化执行逻辑,提升互斥锁性能</td><td>2021年1月31日</td>
</tr>
</table>
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,24 @@ public class SynchronizedAspect {
@Around(value = "@annotation(org.springframework.lock.annotation.Synchronized)")
public Object aroundSynchronized(ProceedingJoinPoint jp) throws Throwable {
Class<?> clz = jp.getTarget().getClass();
Object lock = null;
Object lock = clz;
MethodSignature signature = (MethodSignature) jp.getSignature();
Method method = signature.getMethod();
boolean foundField = false;
if (method == null)
lock = clz;
else {
if (method != null) {
Synchronized annotation = method.getAnnotation(Synchronized.class);
if (annotation == null)
lock = clz;
else{
if (annotation != null){
String varName = annotation.value();
if ("".equals(varName))
lock = clz;
else {
if (!"".equals(varName)) {
for (Field field : clz.getDeclaredFields()) {
field.setAccessible(true);
if (varName.equals(field.getName())){
foundField = true;
lock = field.get(jp.getTarget());
break;
}
}
}
}
}
if (!foundField)
lock = clz;
Object result = null;
synchronized (lock) {
LOGGER.info(clz.getSimpleName() + "获得互斥锁");
Expand Down

0 comments on commit ba558ca

Please sign in to comment.