import javax.interceptor.AroundInvoke; import javax.interceptor.Interceptor; import javax.interceptor.InvocationContext; @Interceptor public class ExecutionTimeInterceptor { @AroundInvoke public Object logExecutionTime(InvocationContext context) throws Exception { long startTime = System.nanoTime(); try { return context.proceed(); } finally { long endTime = System.nanoTime(); long executionTime = endTime - startTime; } } } import javax.ejb.Stateless; import javax.interceptor.Interceptors; @Stateless @Interceptors(ExecutionTimeInterceptor.class) public class MyService { public void doSomething() { } }


上一篇:
下一篇:
切换中文