本帖最后由 HAnG 于 2013-12-19 15:47 编辑  
- new InvocationHandler(){  
 
 -         Collection  target = new ArrayList();
 
 -         @Override  
 
 -         public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {  
 
 -                 long startTime = System.currentTimeMillis();
 
 -                 Object result = method.invoke(target, args);
 
 -                 long endTime = System.currentTimeMillis();
 
 -                 System.out.println(method.getName() + " run for " + (endTime - startTime) + "ms");
 
 -                 return result;
 
 -         }     
 
 - }  
 
  复制代码 
 
动态代理中,在invoke方法里加入运行时间功能。 
运行结果为什么调用每个函数运行时间都是0ms,是我的CPU真有这么快在1毫秒内调用完,还是写错了= = 
求大神解答 
 |