WEB开发网
开发学院软件开发Java Classworking 工具箱: 将 aspect 放到 werk 中 阅读

Classworking 工具箱: 将 aspect 放到 werk 中

 2010-03-18 00:00:00 来源:WEB开发网   
核心提示: 修改了 XML 配置文件以在 traceLong() 的地方使用 traceTimed() advice 方法后,用同样的参数值“6” 运行它完全不显示任何踪迹信息,Classworking 工具箱: 将 aspect 放到 werk 中(9),因为整个执行用时小于最小时

修改了 XML 配置文件以在 traceLong() 的地方使用 traceTimed() advice 方法后,用同样的参数值“6” 运行它完全不显示任何踪迹信息,因为整个执行用时小于最小时间。如果使用值“15”,那么就得到清单 9 所示的输出。

清单 9. 带时间筛选器的输出

Entering fibo(15) 
 Entering fibo(14) 
 Entering fibo(13) 
  Entering fibo(12) 
  Leaving fibo(11)=89 took 2 ms. 
  Leaving fibo(10)=55 took 2 ms. 
  Leaving fibo(12)=144 took 11 ms. 
  Entering fibo(11) 
  Leaving fibo(10)=55 took 2 ms. 
  Leaving fibo(9)=34 took 2 ms. 
  Leaving fibo(11)=89 took 5 ms. 
 Leaving fibo(13)=233 took 19 ms. 
 Entering fibo(12) 
  Leaving fibo(11)=89 took 2 ms. 
  Entering fibo(10) 
  Entering fibo(8) 
   Entering fibo(6) 
   Leaving fibo(4)=3 took 2 ms. 
   Leaving fibo(6)=8 took 4 ms. 
  Leaving fibo(8)=21 took 6 ms. 
  Leaving fibo(10)=55 took 6 ms. 
 Leaving fibo(12)=144 took 10 ms. 
 Leaving fibo(14)=377 took 29 ms. 
 Entering fibo(13) 
 Entering fibo(12) 
  Leaving fibo(11)=89 took 2 ms. 
  Leaving fibo(10)=55 took 2 ms. 
 Leaving fibo(12)=144 took 6 ms. 
 Entering fibo(11) 
  Leaving fibo(10)=55 took 2 ms. 
 Leaving fibo(11)=89 took 3 ms. 
 Leaving fibo(13)=233 took 9 ms. 
Leaving fibo(15)=610 took 95 ms. 
Fibo[15] is 610 

清单 9 输出正是我想要看到的,因此现在可以抛开斐波纳契,转向真正的应用程序了。我将在下个月的专栏中做这件事。

结束语

在本次专栏中,介绍了如何用 AspectWerkz 实现带性能度量增强的基本执行跟踪。下个月的专栏进一步拓展这一概念,扩展跟踪 aspect 并将它应用到复杂的带有自己的内置日志记录的真实世界框架上,以发现 aspect 方法在哪些地方可以很好地发挥作用 —— 在哪些地方不能。aspect 是否可以使我们免于日志记录代码的烦扰?请继续关注并找出答案。

本文示例源代码或素材下载

上一页  4 5 6 7 8 9 

Tags:Classworking 工具箱 aspect

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接