fix thread safety issue

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1200440 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2011-11-10 17:27:52 +00:00
parent 32bfbfe380
commit 8a1245cf41
1 changed files with 8 additions and 1 deletions

View File

@ -252,7 +252,14 @@ public class SearcherLifetimeManager implements Closeable {
* from the same background thread that opens new
* searchers. */
public synchronized void prune(Pruner pruner) throws IOException {
final List<SearcherTracker> trackers = new ArrayList<SearcherTracker>(searchers.values());
// Cannot just pass searchers.values() to ArrayList ctor
// (not thread-safe since the values can change while
// ArrayList is init'ing itself); must instead iterate
// ourselves:
final List<SearcherTracker> trackers = new ArrayList<SearcherTracker>();
for(SearcherTracker tracker : searchers.values()) {
trackers.add(tracker);
}
Collections.sort(trackers);
final long newestSec = trackers.isEmpty() ? 0L : trackers.get(0).recordTimeSec;
for (SearcherTracker tracker: trackers) {