In Java applications statement added tracking technology
Class: Junior
Andrei Malacinski (malacins@us.ibm.com), WebSphere Software Engineer, IBM
January 1, 2001
Now, no matter what projects have strict schedule, and always ask for more features, developers often do not have time or do not take the time to consider debug (or track) strategy. This paper free of charge - Java source code, as well as all the contents - providing developers with a strategy, so they need to realize their own self-designed and tracking strategy, thereby enabling them to concentrate on the main procedures in the application of logic. This paper presents two technologies, one for the development of the track, the other one used to run the track.
Test consider the following situation: Your most loyal, one of the most important customers running the software you have a problem. This report, according to some use when running your application, the application will be terminated accident. Regular customers can reproduce the problem. Customers are not satisfied, and hope that the issue be resolved as soon as possible. Unfortunately, in the development environment or testing environment, you use the same by customers running applications can not return that issue. In all of your normal environment, but the environment, the law has failed to occur. What Next?
In your configuration through the use of run-time tracking technology, such as proposed in this paper, the technique, you can open the client running on the track will be to debug (or track) news output to a file, and then again to re-run an application now, and tracking information sent to you to help you debug their problems. Tracking information will enable you to view proceedings in the customer's environment in the process.
During the discussion before the actual tracking mechanisms, first of all, to see what we will be discussing the two types of tracking.
- Development at the track can be configured your application code, in order to open the application development stage of the output of debugging information as a means of debugging, and deployment of applications will be closed. Your customers will never see the development of tracking information.
To develop a common tracking mechanism is in the building Java source code compiler, set a mark, and this could mark the trigger Java
System.out.println ()call. But you can easily extend this basic model. In the code development, the same embedded run-time tracking you will create tracking function. In addition, it set so that when you close the compiler signs, the development of tracking all calls will be compiled code from the gift.Check. Classbytecode files, documents found in the development of tracking calls does not exist. For the use of this technology for Java source code, as well as instructions, please refer to the "development, tracking mechanisms." - Run-time tracking of your application procedures set up to enable customers to track open source output. If a customer running your application problems, they will be able to open the track, once again running applications, and tracking information sent to you to help you debug their problems.
A simple run-time tracking mechanisms from basic Java
System.out.println ()call composition. But as long as some thought, it can be opened to expand. For example, you can use the run-time customers can be more open-dynamic tracking. In addition, you can also choose to let customers track the output sent to any place, such as console or documents. In achieving these tracking, the creation of a group of you and your partners will be able to enjoy the development of reusable tracking function meaningful. These functions package tracking details, such as where to send output tracking, tracking statements include date / time stamp, and so on. To get a group tracking function and used to illustrate the function of this group tracking Java source code sample, please refer to the "run-time tracking mechanism."
SharedConstants.java, and the final use of the static keyword.) Variables statement that the final (and mandatory) variable values will not change from its initial value of other values.
In the development, DEBUG variables will be set up to the desired output level tracking. In this case, the TRACE_MEDIUM including junior and middle-level tracking, TRACE_HIGH including low, intermediate and advanced tracking, and tracking TRACE_ALL including all levels. TRACE_ALL equivalent TRACE_HIGH. In the deployment of applications, it will be set to TRACE_OFF DEBUG variables. If you use this deployment tracking technology, you may need to define the scope of each level tracking.
Note: When changes either of the above variables, such as the final stage in the development of closed track, you need to be recompiled to use all the variables that Java source code, as well as those who use these variables indirectly code. This step is necessary, because the Java compiler will be passed directly into the values of these variables in the code to use them to optimize your code. Therefore, the compiler will not automatically adopt the necessary checks to determine the need to compile all affected files.
PrintMessage. Packaging support for the development of this class when all the necessary debugging code. Java in your category including PrintMessage such as a category, so that the preparation of the code of each application developers can use the function.
PrintMessage category includes such as following through to the statement, including the development of tracking functions:
Public static final boolean traceMedium = ((SharedConstants.DEBUG & SharedConstants.TRACE_MEDIUM)! = 0)? True: false; public static final boolean traceAll = ((SharedConstants.DEBUG & SharedConstants.TRACE_ALL)! = 0)? True: false;
Note: These variables for the static final statement.
Here is PrintMessage category, it has developed when tracking. Calling them such as printMessageWithDateTime (String msg) and printMessage (String msg), the output of the tracking function to track information on each output.
For the sake of flexibility, in the category of your PrintMessage multiple forms of PrintMessage methods. In the above example:
-
PrintMessage (String msg)Method Invocation, only output target tracking information. -
PrintMessageWithDateTime (String msg)in output tracking information before adding date / time stamp. If you are tracking applications involving database access, network communication, system I / O, or the time stamp will help them to debug complex affairs of the other, then this may be useful. -
PrintMessageNoNewLine (String msg)output without tracking newline trip.
There can be many other forms of methods.
In your source code statements, including tracking, and use your PrintMessage category method. MainApplication.java use of the sample code PrintMessage tracking function to enable the development, debugging.
As a developer, you according to each message in the context of its decision-output tracking.
Note: In order to maintain Java code optimization objectives, the above example direct examination static final variables value. When compiling this code, you can achieve optimization. In this case, the compiler noted that the form of if (Expression) Statement of code, such as expression if (PrintMessage.traceMedium), always come to the same results. The result of the implementation and operation unrelated to the state. Therefore, the compiler can optimize the code. If the compiler notes that if the code block (Expression) conditions always come to some false, it would know the code block will never be part of the implementation of Statement. Therefore, the compiler does not generate Statement block bytecode. Results of this tracking code in the block will not be included in the statement. Class document.
Verify information has been tracking the development of Java compiler removed and therefore not included in the. Class bytecode in the document. To accomplish this step, use a procedure anti-compilation. Class document. Anti-compilation. Class document is compiled from the composition. Class document Java byte code re-created Java source code technology. When the anti-compilation. Class document, check to verify the Java source code tracking information does not exist. Java Development Kit (JDK) provides a javap called anti-assembler. Please click the following ways to implement it:
Javap-c packageName.MyApplication
Note: When you call javap, must be provided. Class packet of documents.
![]()
![]()
![]()
PrintMessage.java example, it implements the technology, a change in form. This class support package running all the necessary debugging code. IsRunTimeDebugOn common method () returns the value of the static variable debugOn, this value is initialized in the class load. Then isRunTimeDebugOn () method calls will not bring too much of the spending, as the only way to return to a variable value.
In your source code statements included in the tracking and the use of PrintMessage category method. For example, see the sample code MainApplication.java a change in form, it uses the tracking function PrintMessage opening runtime debugging.
By the way your customers start your Java application, as follows:
Jre-Ddebug = 1 MainApplication
Or
Java-Ddebug = 1 MainApplication
If your application through from the front of executable programs (such as C / C + + code) or script start to hide on the JVM Java Virtual Machine (JVM) call, you can use slightly different ways of debugging variables show to the customer. In your executable program or script logic, you will be using the above variables debug start-up JVM.
You can use the following methods enhance this basic design:
- Debugging variables customers can track the value of the output location (such as the system console or a fully qualified document). This will enable customers in the collection of output tracking with greater flexibility, tracking output can be sent to you and your application development team to help you debug.
- Variables can also specify output tracking levels (such as low, medium or high). Junior and middle-level tracking could include tracking of application-specific point tracking, and advanced tracking could also include methods of entry and exit notice, or notice iterative cycle. - The definition and meaning of your decision.
- If your application is divided into a number of logical components, debugging variables can be designated to track which application components.
Note: The above information can be included in a single variable, can also use different variables are designated. For example, using a variable output designated location to another level tracking variables specified, and then specify a variable tracking components.
Please refer to PrintMessage.java sample source code form of this change, it will be tracked through a statement in the document output to achieve the technology. In this case, if the designated debugging variables, it is interpreted as the value of fully qualified file name. In practical application, it should be in the file I / O part of the additional error checking and error recovery functions. Also, if you expect there will be a lot of follow-up statement, it can restrict the size of the paper. A strategy is that once reached file size limits, the first document on the removal of the blocks, so as to add a new phrase to space. This technology will be further changed again, you can through the application's user interface will be presented to tracking customers. Your interface will allow users to choose between tracking, tracking the location of the output, file name, file size limitations, the paper Qiduan mechanisms, and so on.
![]()
![]()
![]()
original English text.
- "Implementing Assertions for Java," Dr Dobb's Journal, including one on "Design by Contract," Deputy column.
- Through C / C + + User's Journal can be found several assertions relating to the C + + article.
- "Exceptions in Java," the authors Bill Venners.
- Lesson: Handling Errors with Exceptions, from the Sun Microsystems Java tutorial.
malacins@us.ibm.com and can be linked.
Tags: Statement, the core java technology






