Java Reference
In-Depth Information
The time here is for 100 executions of the loop with a classname list of 1,500 classes. There
are a few interesting conclusions to draw here. First, the more complex code in JDK 7 (to en-
able the parallel loading) has actually introduced a small penalty in the simplest caseā€”an ex-
ample of the principle that simpler code is faster. Even with two threads, the new model is
slightly slower in this case, because the code spends virtually no time in the parent classload-
er: the time spent while the lock is held in the parent classloader is greatly outweighed by the
time spent elsewhere in the program.
When there are four threads, things change. To begin, the four threads here are competing for
CPU cycles against other processes on the four-CPU machine (in particular, there is a
browser displaying a flash-enabled page, which is taking some 40% of a single CPU). So
even in the JDK 7 case, the scaling isn't linear. But at least the scaling is much better: in the
JDK 6 case, there is now severe contention around the parent classloader lock.
There are two reasons for that contention. First, competition for the CPU has effectively in-
creased the amount of time the classloader lock is held, and second, there are now twice as
many threads competing for the lock.
Increasing the size of the system classpath also greatly increases the length of time the parent
classloading lock is held. Table 12-3 repeats this experiment when the classpath has 266
entries (the number of JAR files in the GlassFish distribution). (GlassFish doesn't simply put
all those files into a single classloader; it has been chosen here simply as an expedient ex-
Table 12-3. Time to load classes concurrently (long classpath)
Number of threads Time in JDK 7 Time in JDK 6
98.146 seconds 92.129 seconds
111.16 seconds 316.01 seconds
150.98 seconds 708.24 seconds
287.97 seconds 1461.5 seconds
Now, the contention even with only two threads is quite severe: without a parallel-enabled
classloader, it takes three times longer to load the classes. And as load is injected into the
already-stressed system, scaling becomes even worse. In the end, performance is as much as
seven times slower.
Search WWH ::

Custom Search