import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class ServiceSlowInterceptor {
private Log logger = LogFactory.getLog(ServiceSlowInterceptor.class);
@Pointcut("execution(* com.xuyi..dao..*(..))")
public void logger() {
}
@Around("com.xuyi.ServiceSlowInterceptor.logger()")
public Object invoke(ProceedingJoinPoint pjp) throws Throwable {
Object result = null;
Date startDate = null;
Map<String, Object> infoMap = null;
String targetName = null;
if (logger.isDebugEnabled()) {
targetName = String.valueOf(pjp);
infoMap = new HashMap<String, Object>();
Object[] argArray = pjp.getArgs();
for (int i = 0; i < argArray.length; i++) {
infoMap.put(String.valueOf(i), argArray[i]);
}
startDate = new Date();
}
try {
// 执行处理
result = pjp.proceed();
} finally {
if (logger.isDebugEnabled()) {
Date endDate = new Date();
if (endDate.getTime() - startDate.getTime() > 60000) {
logger.debug("方法:" + targetName + "处理时间属于系统缓慢时间设定:" + infoMap);
}
}
}
return result;
}
}