2017-09-04 117 views
1

下面的代码花费了更多时间来降低整体应用程序的性能。AOP性能问题

@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秒。为什么?

是时间从毫秒转换为微秒 性能问题。

在此先感谢。

回答

0

使用System.nanoTime()System.currentTimeMillis()而不是Calendar.getInstance().getTimeInMillis()