package org.mobiletrain.interceptor;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
/**
* struts2拦截器继承AbstractInterceptor类
* @author czy
*
*/
public class PerfInterceptor extends AbstractInterceptor {
/* 重写intercept方法*/
@Override
public String intercept(ActionInvocation invocation)
throws Exception {
long start = System.currentTimeMillis();
//在执行原方法的前后进行时间计算
String result = invocation.invoke();
long end = System.currentTimeMillis();
String name = invocation.getInvocationContext().getName();
System.out.println(name + "总耗时为: " + (end - start) + "ms");
return result;
}
}
网友评论