fix: 日志切面中ThreadLocal可能引发的内存泄漏

pull/787/head
snow 2023-02-08 19:46:15 +08:00
parent f3cdf8ccfc
commit 8bd547e79d
1 changed files with 13 additions and 8 deletions

View File

@ -29,6 +29,7 @@ import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
/**
@ -65,9 +66,13 @@ public class LogAspect {
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
Object result;
currentTime.set(System.currentTimeMillis());
Log log;
try {
result = joinPoint.proceed();
Log log = new Log("INFO",System.currentTimeMillis() - currentTime.get());
log = new Log("INFO", System.currentTimeMillis() - currentTime.get());
} finally {
currentTime.remove();
}
HttpServletRequest request = RequestHolder.getHttpServletRequest();
logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request), joinPoint, log);
return result;