Java Reference
In-Depth Information
Listing 12.9. Test Method to Verify Thread Pool Expansion.
12.1.6. Generating More Interleavings
Since many of the potential failures in concurrent code are low-probability events, testing
for concurrency errors is a numbers game, but there are some things you can do to improve
your chances. We've already mentioned how running on multiprocessor systems with fewer
processors than active threads can generate more interleavings than either a single-processor
system or one with many processors. Similarly, testing on a variety of systems with different
processor counts, operating systems, and processor architectures can disclose problems that
might not occur on all systems.
A useful trick for increasing the number of interleavings, and therefore more effectively ex-
ploring the state space of your programs, is to use Thread.yield to encourage more con-
text switches during operations that access shared state. (The effectiveness of this technique
is platform-specific, since the JVM is free to treat Thread.yield as a no-op [JLS 17.9];
Search WWH ::




Custom Search