Mercurial Hosting > luan
changeset 1502:8a7b6b32c691
minor threads
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 10 May 2020 22:48:15 -0600 |
parents | e66e3d50b289 |
children | 74c534de211f |
files | src/goodjava/lucene/backup/BackupIndexWriter.java src/goodjava/lucene/backup/BackupServer.java src/goodjava/lucene/logging/LoggingIndexWriter.java src/goodjava/webserver/Server.java |
diffstat | 4 files changed, 9 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/goodjava/lucene/backup/BackupIndexWriter.java Sun May 10 22:28:13 2020 -0600 +++ b/src/goodjava/lucene/backup/BackupIndexWriter.java Sun May 10 22:48:15 2020 -0600 @@ -44,7 +44,7 @@ super.commit(); //sync(); if( !isSyncPending ) { - new Thread(sync).start(); + threadPool.execute(sync); isSyncPending = true; } }
--- a/src/goodjava/lucene/backup/BackupServer.java Sun May 10 22:28:13 2020 -0600 +++ b/src/goodjava/lucene/backup/BackupServer.java Sun May 10 22:48:15 2020 -0600 @@ -5,8 +5,8 @@ import java.util.Map; import java.net.Socket; import java.net.ServerSocket; -import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.Executors; +import java.util.concurrent.ExecutorService; import javax.net.ssl.SSLServerSocketFactory; import javax.net.ssl.SSLServerSocket; import goodjava.util.SoftCacheMap; @@ -39,7 +39,7 @@ } private final File backupDir; - private static final ThreadPoolExecutor threadPool = (ThreadPoolExecutor)Executors.newCachedThreadPool(); + private static final ExecutorService threadPool = Executors.newCachedThreadPool(); private static final Map<String,Backup> backups = new SoftCacheMap<String,Backup>(); public BackupServer(File backupDir) throws IOException {
--- a/src/goodjava/lucene/logging/LoggingIndexWriter.java Sun May 10 22:28:13 2020 -0600 +++ b/src/goodjava/lucene/logging/LoggingIndexWriter.java Sun May 10 22:48:15 2020 -0600 @@ -13,6 +13,8 @@ import java.util.List; import java.util.ArrayList; import java.util.Random; +import java.util.concurrent.Executors; +import java.util.concurrent.ExecutorService; import org.apache.lucene.document.Document; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; @@ -43,6 +45,7 @@ private static final int OP_ADD_DOCUMENT = 3; private static final int OP_UPDATE_DOCUMENT = 4; private static final Random rnd = new Random(); + protected static final ExecutorService threadPool = Executors.newCachedThreadPool(); public final LuceneIndexWriter indexWriter; private final File logDir; @@ -343,7 +346,7 @@ } if( logs.size() > 3 ) { isMerging = true; - new Thread(mergeLogs).start(); + threadPool.execute(mergeLogs); // mergeLogs.run(); } }
--- a/src/goodjava/webserver/Server.java Sun May 10 22:28:13 2020 -0600 +++ b/src/goodjava/webserver/Server.java Sun May 10 22:48:15 2020 -0600 @@ -5,8 +5,8 @@ import java.net.ServerSocket; import java.net.InetAddress; import java.net.UnknownHostException; -import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.Executors; +import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; import goodjava.logging.Logger; import goodjava.logging.LoggerFactory; @@ -17,7 +17,7 @@ public final int port; public final Handler handler; - public static final ThreadPoolExecutor threadPool = (ThreadPoolExecutor)Executors.newCachedThreadPool(); + public static final ExecutorService threadPool = Executors.newCachedThreadPool(); public Server(int port,Handler handler) { this.port = port;