Errata

Java Extreme Programming Cookbook

Errata for Java Extreme Programming Cookbook

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.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
Printed Page 83
Example 4-11

This test can miss the completion of the search if it happens quickly (or, perhaps, in a higher priority thread).

The code:

// 1. Execute the search
sm.search("eric", mockListener);

// 2. Wait for the search to complete
synchronized (mockListener) {
mockListener.wait(2000);
}

should be replaced by:

// 1. Execute the search
synchronized (mockListener) {
sm.search("eric", mockListener);

// 2. Wait for the search to complete
mockListener.wait(2000);
}

This prevents the search thread from calling the notifyAll() method before the corresponding wait() method is called.

Another, possibly better solution, is to replace the getSearchModelEvent method in Example 4-10 with one that waits itself:

public synchronized SearchModelEvent waitForSearchModelEvent (long timeout) throws InterruptedException {
if (this.evt == null) wait (timeout);
return this.evt;
}

This method also works in the case where the search is performed in the calling thread (which would fail in the existing implementation).

Anonymous