timoutinterceptor.java
来自「加拿大达内科技有限公司配需java程序员的上课时的代码」· Java 代码 · 共 27 行
JAVA
27 行
package exec;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
public class TimoutInterceptor implements MethodInterceptor{
private long timeout;
public void setTimeout(long timeout) {
this.timeout = timeout;
}
public Object invoke(MethodInvocation arg0) throws Throwable {
// TODO Auto-generated method stub
long startTime = System.currentTimeMillis();
Object rst = arg0.proceed();
long endTime = System.currentTimeMillis();
long time = endTime - startTime;
if(time > timeout)
System.out.println("time out!");
else
System.out.println("execute time is:"+time);
return rst;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?