Java Performance: The Definitive Guide

Errata for Java Performance: The Definitive Guide

Submit your own errata for this product.


The errata list is a list of errors and their corrections that were found after the product was released. If the error was corrected in a later version or reprint the date of the correction will be displayed in the column titled "Date Corrected".

The following errata were submitted by our customers and approved as valid errors by the author or editor.

Color Key: Serious Technical Mistake Minor Technical Mistake Language or formatting error Typo Question Note Update



Version Location Description Submitted By Date Submitted Date Corrected
PDF
Page xi
4th paragraph

says 'Paralellizing', should be Parallellizing

Note from the Author or Editor:
Actually, should be parallelizing

Roger Schildmeijer  May 18, 2014 
Other Digital Version
Basic VM Information
Basic VM Information

The string "other_options" is not part of the command % java other_options -XX:+PrintFlagsFinal -version If we run the command using "other_options" we will get: Error: Could not find or load main class other_options But if we run the command without this string: % java -XX:+PrintFlagsFinal -version then it works. Clearly "other_options" it is meta information related to some possible options. It is not clear what other options we can use, though. Thank you, -Rod Oliveira

Note from the Author or Editor:
On page 48 of the printed version, in the command % java other_options -XX:+PrintFlagsFinal -version please set other_options in constant width italic Change the first sentence of the next paragraph to read You should include any other JVM options you intend to use on the command line because setting some options (particularly when setting GC-related flags) will affect the final value of other options.

Rod Oliveira  May 27, 2014 
Printed
Page 197
code example

The WeakHahMap defined in ImmutableObject should be a static field instead of an instance field. In other words, there should be one map that all the instances use instead of a map per immutable object.

Note from the Author or Editor:
Change the line reading: WeakHashMap<ImmutableObject, ImmutableObject> map = new WeakHashMap(); to private static WeakHashMap<ImmutableObject, ImmutableObject> map = new WeakHashMap();

Chris Grindstaff  Jun 21, 2014 
Printed
Page 197
code example

The values in the WeakHashMap should be weakly referenced . Hence, WeakHashMap<ImmutableObject, WeakReference<ImmutableObject>> should be used instead of WeakHashMap<ImmutableObject, ImmutableObject>. See also the documentation of WeakHashMap (http://docs.oracle.com/javase/8/docs/api/java/util/WeakHashMap.html): "Implementation note: The value objects in a WeakHashMap are held by ordinary strong references. Thus care should be taken to ensure that value objects do not strongly refer to their own keys, either directly or indirectly, since that will prevent the keys from being discarded. Note that a value object may refer indirectly to its key via the WeakHashMap itself; that is, a value object may strongly refer to some other key object whose associated value object, in turn, strongly refers to the key of the first value object. If the values in the map do not rely on the map holding strong references to them, one way to deal with this is to wrap values themselves within WeakReferences before inserting, as in: m.put(key, new WeakReference(value)), and then unwrapping upon each get." For example, WeakHashMap<Object, Object> map = new WeakHashMap<>(); while(true) { Object o = new byte[1000000]; map.put(o,o); } runs immediately out of memory while WeakHashMap<Object, WeakReference<Object>> map = new WeakHashMap<>(); while(true) { Object o = new byte[1000000]; map.put(o,new WeakReference(o)); } does not, because it allows for continuous garbage collection.

Note from the Author or Editor:
Change the code line reading map.put(io, io); to map.put(io, new WeakReference(io));

Otmar Ertl  Jul 16, 2014 
Printed
Page 364
1st sentence

"f you are interesting in... Should be If you are interested in...

Rick Orr  May 21, 2014 
Printed, Safari Books Online
Page 383
4th Paragraph

The text contains this wording: "it tests to see if the second character is A" but as the example shows, it should be "it tests to see if the second character is not A"

Scott Oaks
O'Reilly Author 
May 23, 2014 
Printed
Page 384
code example (countSymbols)

The code example public int countSymbols(ArrayList<String> al) { int count = 0; t = al.stream(). filter(symbol -> symbol.charAt(0) != 'A' && symbol.charAt(1) != 'A' && symbol.charAt(2) != 'A' && symbol.charAt(3) != 'A'). forEach(symbol -> count++); return count; } has some flaws: 1) The return type of forEach is void, hence the assignment to "t" (which is neither declared nor used) is invalid. 2) The "count" variable cannot be modified within the lambda expression, because it is effectively final. The stream class provides a count() method which can be used instead: public int countSymbols(ArrayList<String> al) { return (int) al .stream() .filter( symbol -> symbol.charAt(0) != 'A' && symbol.charAt(1) != 'A' && symbol.charAt(2) != 'A' && symbol.charAt(3) != 'A') .count(); }

Note from the Author or Editor:
The first implementation of the countSymbols method should be replaced with this: private static long countFilter(ArrayList<String> al) { long then = System.currentTimeMillis(); Stream<String> stream = al.stream(); stream.filter( symbol -> symbol.charAt(0) != 'A' && symbol.charAt(1) != 'A' && symbol.charAt(2) != 'A' && symbol.charAt(3) != 'A'). forEach(symbol -> { count++; }); long now = System.currentTimeMillis(); return now - then; } The second example (immediately following) should be replaced with this: private static long countIterator(ArrayList<String> al) { long then = System.currentTimeMillis(); for (String symbol : al) { if (symbol.charAt(0) != 'A' && symbol.charAt(1) != 'A' && symbol.charAt(2) != 'A' && symbol.charAt(3) != 'A') count++; } return System.currentTimeMillis() - then; }

Otmar Ertl  Jul 29, 2014 
Printed
Page 385
Table 12-11

Implemementation should be Implementation

Note from the Author or Editor:
Implemementation should be Implementation

Otmar Ertl  Jul 29, 2014