Java Reference
In-Depth Information
fying which locks are causing contention, but in practice these features are often a blunter
instrument than is desired for analyzing a program's locking behavior.)
The built-in JMX agent also offers some limited features for monitoring thread behavior. The
ThreadInfo class includes the thread's current state and, if the thread is blocked, the lock
or condition queue on which it is blocked. If the “thread contention monitoring” feature is
enabled (it is disabled by default because of its performance impact), ThreadInfo also in-
cludes the number of times that the thread has blocked waiting for a lock or notification, and
the cumulative amount of time it has spent waiting.
Summary
Testing concurrent programs for correctness can be extremely challenging because many of
the possible failure modes of concurrent programs are low-probability events that are sens-
itive to timing, load, and other hard-to-reproduce conditions. Further, the testing infrastruc-
ture can introduce additional synchronization or timing constraints that can mask concur-
rency problems in the code being tested. Testing concurrent programs for performance can
be equally challenging; Java programs are more difficult to test than programs written in stat-
ically compiled languages like C, because timing measurements can be affected by dynamic
compilation, garbage collection, and adaptive optimization.
To have the best chance of finding latent bugs before they occur in production, combine tra-
ditional testing techniques (being careful to avoid the pitfalls discussed here) with code re-
views and automated analysis tools. Each of these techniques finds problems that the others
are likely to miss.
Search WWH ::




Custom Search