Java Reference
In-Depth Information
. count ();
}
}
The first part of this exercise is to refactor the blocking return code to use a callback inter-
face. In this case, we'll be using a Consumer<Boolean> . Remember that Consumer is a func-
tional interface that ships with the JVM that accepts a value and returns void . Your mission,
should you choose to accept it, is to alter BlockingArtistAnalyzer so that it implements
ArtistAnalyzer ( Example 9-19 ) .
Example 9-19. The ArtistAnalyzer that you need to make BlockingArtistAnalyzer implement
public
public interface
interface ArtistAnalyzer
ArtistAnalyzer {
public
public void
void isLargerGroup ( String artistName ,
String otherArtistName ,
Consumer < Boolean > handler );
}
Now that we have an API that fits into the callback model, we can remove the need for both
of the blocking lookups to happen at the same time. You should refactor the isLargerGroup
method so that they can operate concurrently using the CompletableFuture class.
Search WWH ::




Custom Search