comparison src/goodjava/lucene/logging/LoggingIndexWriter.java @ 1502:8a7b6b32c691

minor threads
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 10 May 2020 22:48:15 -0600
parents e66e3d50b289
children f443542d8650
comparison
equal deleted inserted replaced
1501:e66e3d50b289 1502:8a7b6b32c691
11 import java.util.Set; 11 import java.util.Set;
12 import java.util.HashSet; 12 import java.util.HashSet;
13 import java.util.List; 13 import java.util.List;
14 import java.util.ArrayList; 14 import java.util.ArrayList;
15 import java.util.Random; 15 import java.util.Random;
16 import java.util.concurrent.Executors;
17 import java.util.concurrent.ExecutorService;
16 import org.apache.lucene.document.Document; 18 import org.apache.lucene.document.Document;
17 import org.apache.lucene.index.DirectoryReader; 19 import org.apache.lucene.index.DirectoryReader;
18 import org.apache.lucene.index.IndexReader; 20 import org.apache.lucene.index.IndexReader;
19 import org.apache.lucene.index.Term; 21 import org.apache.lucene.index.Term;
20 import org.apache.lucene.search.IndexSearcher; 22 import org.apache.lucene.search.IndexSearcher;
41 private static final int OP_DELETE_ALL = 1; 43 private static final int OP_DELETE_ALL = 1;
42 private static final int OP_DELETE_DOCUMENTS = 2; 44 private static final int OP_DELETE_DOCUMENTS = 2;
43 private static final int OP_ADD_DOCUMENT = 3; 45 private static final int OP_ADD_DOCUMENT = 3;
44 private static final int OP_UPDATE_DOCUMENT = 4; 46 private static final int OP_UPDATE_DOCUMENT = 4;
45 private static final Random rnd = new Random(); 47 private static final Random rnd = new Random();
48 protected static final ExecutorService threadPool = Executors.newCachedThreadPool();
46 49
47 public final LuceneIndexWriter indexWriter; 50 public final LuceneIndexWriter indexWriter;
48 private final File logDir; 51 private final File logDir;
49 protected final List<LogFile> logs = new ArrayList<LogFile>(); 52 protected final List<LogFile> logs = new ArrayList<LogFile>();
50 private LogOutputStream log; 53 private LogOutputStream log;
341 writeIndex(); 344 writeIndex();
342 setLog(); 345 setLog();
343 } 346 }
344 if( logs.size() > 3 ) { 347 if( logs.size() > 3 ) {
345 isMerging = true; 348 isMerging = true;
346 new Thread(mergeLogs).start(); 349 threadPool.execute(mergeLogs);
347 // mergeLogs.run(); 350 // mergeLogs.run();
348 } 351 }
349 } 352 }
350 353
351 public synchronized void rollback() throws IOException { 354 public synchronized void rollback() throws IOException {