peeking inside the box: attribute-oriented programming with java 1.5
in the previous article, i also defined a new annotation, @status, which i used throughout my code to associate methods with user-readable status messages. for example: 【程序编程相关:优化代码,看看哪个执行速度更快!!!】
in the previous article in this series, "peeking inside the box, part 1," i introduced the concepts of attribute-oriented programming, java 1.5 annotations, and bytecode instrumentation. i used these concepts to provide a jstatusbar gui component that reports on the progress of an application without any explicit code. in this article i will introduce a completely different implementation of the same jstatusbar that uses thread sampling rather than bytecode instrumentation. i will then combine the two practices to develop a solution that has the best features of each. 【推荐阅读:我的内容管理系统(CMS)寻找历程 --】
as discussed in the previous article, i may want to write additional code which uses the @status annotations for a different purpose. let´s consider the additional requirement that our application must catch all unhandled exceptions and display them to the user. rather than providing a java stack trace, however, it should only display methods that have a @status annotation, and it should not show any code artifacts (class or method names, line numbers, etc.). 【扩展信息:在ASP.NET FORUMS中一种存储】
@status("connecting to database") public void connecttodb (string url) { ... }exception handling
for example, consider the following stack trace:
... 下一页