文章目录
通过日志监控service执行时间利用aop实现创建service的监控Thread.sleep(毫秒): 使线程挂起
通过日志监控service执行时间
利用aop实现
创建service的监控
package com
.beyond
.aspect
;
import org
.aspectj
.lang
.ProceedingJoinPoint
;
import org
.aspectj
.lang
.annotation
.Around
;
import org
.aspectj
.lang
.annotation
.Aspect
;
import org
.slf4j
.Logger
;
import org
.slf4j
.LoggerFactory
;
import org
.springframework
.stereotype
.Component
;
@Aspect
@Component
public class ServiceLogAspect {
public static final Logger log
=
LoggerFactory
.getLogger(ServiceLogAspect
.class);
@Around("execution(* com.beyond.service.impl..*.*(..))")
public Object
recordTimeLog(ProceedingJoinPoint point
) throws Throwable
{
log
.info("========= 开始执行 {}.{} ========",
point
.getTarget().getClass(),
point
.getSignature().getName());
long begin
= System
.currentTimeMillis();
Object result
= point
.proceed();
long end
= System
.currentTimeMillis();
long takeTime
= end
- begin
;
if (takeTime
>3000){
log
.error("========== 执行结束, 耗时:{} 毫秒==========",takeTime
);
}else if (takeTime
>2000){
log
.warn("========== 执行结束, 耗时:{} 毫秒==========",takeTime
);
}else {
log
.info("========== 执行结束, 耗时:{} 毫秒==========",takeTime
);
}
return result
;
}
}
Thread.sleep(毫秒): 使线程挂起
转载请注明原文地址:https://blackberry.8miu.com/read-383.html