以下代码花费更多时间来降低整体应用程序性能。
@Aspect
@Component
public class LoggingHandler {
/**
* Logger initialization.
*
*/
private final Logger logger = LoggerFactory.getLogger(LoggingHandler.class);
/**
* Around advise for SlingAdapterImpl.
* @param pjp joinPoint
* @return response
* @throws Throwable exception
*/
@Around("execution(* com.abcd.oicp.storage.client.impl.SlingAdapterImpl.*(..))")
public Object logAroundAllMethods(ProceedingJoinPoint pjp) throws Throwable {
long startTime = Calendar.getInstance().getTimeInMillis();
Object obj = null;
try {
obj = pjp.proceed();
} finally {
logger.info("Method={} Time taken={} micro secs", pjp.getSignature().getName(),
(TimeUnit.MILLISECONDS.toMicros(Calendar.getInstance().getTimeInMillis() - startTime)));
}
return obj;
}
}
在JMeter中,耗时约1.5秒。为什么?
时间从毫秒转换为微秒a 绩效问题。
提前感谢。
答案 0 :(得分:0)
使用System.nanoTime()
或System.currentTimeMillis()
代替Calendar.getInstance().getTimeInMillis()