Tracing in a multithreaded, multiplatform environment
In \"Use a consistent trace system for easier debugging,\" Scott Clee showed you how to trace and log from a custom class to provide a consistent tracing approach across your applications. This approa
Tutorial Details:
Log4j is easy to set up: all you need to do is supply the log4j JAR files to each piece of your application and get on with logging (see Downloading and installing log4j). The use of log4j is explained in its documentation, and there are a few articles looking at its basic usage (see Resources for a link). In this article, I will talk about the things that you need to consider for logging in a complex environment, and show you how to use the facilities provided in log4j to best effect in the context of a working example. I will also show you how to mine the log information once it has been gathered. Even with the best planning in the world, it can still be time consuming and tricky to find the information you\'re looking for in a large log file.
Why is multithreading a big deal?
If your program runs on several threads simultaneously, the logging information from each can become tangled up. Anyone who has tried reading output from 15 interleaved threads knows what I mean! In addition, your code might often be running in a distributed system on multiple machines. If you\'re using the same trace system for all your components, you\'ll be left to tie together multiple outputs from systems with potentially unsynchronized internal clocks. (This last issue is a real gotcha. Imagine reading through trace information, not realizing that the timestamps on your client machine are all 20 seconds earlier than the equivalent timestamps on the server!)
Listing 1 is an example of trace information coming from a single program being run using a simple output using timestamps and messages. It\'s much like the output you might see if you rolled your own logging infrastructure.
Listing 1. Trace information for a simple application
(12:01:02) Starting
(12:01:02) initializing variables
(12:01:03) making call to db
(12:01:04) got value \'A\'
(12:01:05) setting new value to db
(12:01:05) done
That all seems straightforward enough. But now look at Listing 2, which shows what happens when you scale up and run five threads at the same time.
Read
Tutorial at: Click here to view the tutorial
Rate Tutorial: Tracing in a multithreaded, multiplatform environment
View Tutorial: Tracing in a multithreaded, multiplatform environment
Related
Tutorials:
JavaWorld - Distributed
applet-based
massively parallel processing
(DAMPP) - January
1997
JavaWorld - Distributed
applet-based
massively parallel processing
(DAMPP) - January
1997 |
Programming Java threads in the
real world, Part
1 - JavaWorld -
September 1998
Programming Java threads in the
real world, Part
1 - JavaWorld -
September 1998 |
Programming Java threads in the
real world, Part
7 - JavaWorld -
April 1999
Programming Java threads in the
real world, Part
7 - JavaWorld -
April 1999 |
Write
high-performance RMI servers and Swing clients - JavaWorld - April 1999
Write
high-performance RMI servers and Swing clients - JavaWorld - April 1999 |
The Java HotSpot
Performance Engine is set to break new records - JavaWorld
The Java HotSpot
Performance Engine is set to break new records - JavaWorld |
Simple
handling of network timeouts - JavaWorld
September 1999
Simple
handling of network timeouts - JavaWorld
September 1999 |
Agents talking to
agents - JavaWorld September
1998
Agents talking to
agents - JavaWorld September
1998 |
Debug with jdb -
JavaWorld June
2000
Debug with jdb -
JavaWorld June
2000 |
Log4j delivers
control over logging - JavaWorld November 2000
Log4j delivers
control over logging - JavaWorld November 2000 |
Double-checked
locking: Clever, but broken - JavaWorld February
2001
Double-checked
locking: Clever, but broken - JavaWorld February
2001 |
Finalists announced for
JavaWorld
Editors' Choice Awards
Finalists announced for
JavaWorld
Editors' Choice Awards |
Master J2ME for live data
delivery
Master J2ME for live data
delivery |
J2ME devices:
Real-world performance
J2ME devices:
Real-world performance |
Add concurrent processing with message-driven beans
Add concurrent processing with message-driven beans |
Tracing in a multithreaded, multiplatform environment
Tracing in a multithreaded, multiplatform environment
In \"Use a consistent trace system for easier debugging,\" Scott Clee showed you how to trace and log from a custom class to provide a consistent tracing approach across your applications. This approa |
YourKit Java Profiler 2.5.2 Released
YourKit Java Profiler 3.2 Released
With help of YourKit Java Profiler, an outstanding tool for Java professionals, you can easily solve wide range of CPU and memory related performance problems in J2EE and J2SE applications.
|
Build scripts with Groovy and Ant
Build scripts with Groovy and Ant
Summary
In nearly all developers' toolboxes, Ant is the standard build tool for Java applications, thanks to its open, standard, and multiplatform structure. Though it represents a great improvement in automating produc |
YourKit Java Profiler 3.2 Released
With help of YourKit Java Profiler, an outstanding tool for Java professionals, you can easily solve wide range of CPU and memory related performance problems in J2EE and J2SE applications. |
Using JConsole to Monitor Applications
JConsole is the Java Monitoring and Management Console, a new graphical tool shipped in J2SE JDK 5.0. This article describes how JConsole can be used to observe information about an application running on the Java platform, with an overview of the J2SE 5. |
Source Code for Solaris OS Available Through OpenSolaris Program
Sun will release Solaris code under the newly OSI-approved Common Development and Distribution License (CDDL), based on the Mozilla Public License (MPL). You can now find Solaris Dynamic Tracing (DTrace) code on the OpenSolaris.org site, which is open for |
|
|
|