comparison src/goodjava/lucene/logging/LoggingIndexWriter.java @ 1504:f443542d8650

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