我在Java中使用CXF实现了一个可用的SOAP Web服务。在服务器端计算方法执行的好方法是什么?Web服务请求执行时间计算
我现在所做的是我用的拦截器。我在InInterceptor(Phase.RECEIVE)中定义了public static long start
。在我OutInterceptor(Phase.SEND)我计算响应时间是这样的:
@Override
public void handleMessage(Message arg0) {
long stop = System.currentTimeMillis();
long executionTime = stop - RequestStartInterceptor.start;
System.out.println("execution time was ~" + executionTime + " ms");
}
有没有更好的方式来做到这一点?我正在阅读关于方法低谷代理的执行情况,但我不知道如何做到这一点。
问题更新:
我GOOGLE了一下更多使用代理即找到我的路约于第二种方式:基于迄今为止的意见对这个问题
@Aspect
public class MyServiceProfiler {
@Pointcut("execution(* gov.noaa.nhc.*.*(..))")
public void myServiceMethods() { }
@Around("myServiceMethods()")
public Object profile(ProceedingJoinPoint pjp) throws Throwable {
long start = System.currentTimeMillis();
System.out.println("Going to call the method.");
Object output = pjp.proceed();
System.out.println("Method execution completed.");
long elapsedTime = System.currentTimeMillis() - start;
System.out.println("Method execution time: " + elapsedTime + " milliseconds.");
return output;
}
}
,使用拦截器是比使用代理更好。我希望尽可能减慢Web服务的速度(这肯定会减慢速度),同时获得精确的性能测量。
我觉得上面的机制很好。 –
我推荐拦截器 – mtraut