The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

hgbirken (1) [Avatar] Offline
chapter 11.2, Listing 11.5, presents the class SearcherManager which is intended to manage reopening IndexSearcher in a multithreaded environment. The provided sample class has been successfully tested and it works. Nevertheless I have a question abbout the implementing details of SearcherManager.

Why don't you simply add the synchronized keyword to the declaration of the maybeReopen() method instead of invoking the methods startReopen() and doneReopen()?

Best regards
HG Birken
mike.mccandless (221) [Avatar] Offline
Re: SearcherManager - Thread safety
The issue is that reopen can be time consuming in general; so if we made maybeReopen sync'd, this would unnecessarily block searches from calling get/release.