Discuss 5 ways to track Java execution

Source: Internet
Author: User

Zviki Cohen publishes 5 ways to track Java execution based on his own experience of exploring and understanding the code that others have written. He found that simple reading of source code (in some cases, decompile code) could be a tedious and erroneous process. Instead, he recommends 5 different run-time tracking methods to observe when Java code is running, eliminating many of the disadvantages of learning other people's code. The following condensed his 5 recommendations:

1, the Basic method: Breakpoint and Single Step execution

"Start in the simplest way: Set breakpoints and start tracking your program execution." It's best at these times: you need a quick and easy solution, you have all the code and you know where you want to stop. You need to set fine information (parameters, local variables, and so on) at a given breakpoint. ”

2. Primary method: Debug Message

"We continue to track the program by setting up debug messages." The easiest way to do this is to print the message to the console using the SYSTEM.OUT.PRINTLN statement. It's best at these times: you have the code and you know exactly what you're looking for. This is a very good solution for the event handler. When it runs through the execution of a complex process, its high performance is useful for understanding which events are triggered. ”

3. Popular methods: Dynamic proxy

"This is an improvement over simple debugging messages. A dynamic proxy is a specific Java feature that allows a developer to introduce a proxy class, before adding a given class, and intercepting all calls through a given interface. It's best at these times: it's a great solution for event handlers. You can set up a virtual event handler in a very short time with a normal agent to see the sequence of events occurring. This is the simplest and quickest way to understand an event handler. ”

4. Methods of Violence: Runtime Profiler (Run-time Profiler)

The profiler is a powerful tool for tracking all calls through a particular JVM hooks in the system. But using it to track the execution process is very small. It is best at these times: you want a complete picture of a particular operation (e.g., very short execution flow). ”

5. New era: Aspects

"Aspect-oriented programming (Aspect oriented PROGRAMMING--AOP) is an extraordinary idea. There is no need to delve into the aspect concept, here only its capabilities: it is a quick and easy way to intercept your code execution. You can selectively set hooks around methods, constructors, property access, and so on, without having to modify the original code. In these hooks, you can print debug messages. It's best at these times: you want to track code execution that can be rebuilt. ”

By February 2007, Zviki Cohen, a Amdocs architect and senior advisor, is now a private entrepreneur in the software world.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.