[ https://issues.apache.org/jira/browse/OPENNLP-1224?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16686104#comment-16686104 ]
ASF GitHub Bot commented on OPENNLP-1224: ----------------------------------------- kojisekig closed pull request #338: OPENNLP-1224 Daemon threads URL: https://github.com/apache/opennlp/pull/338 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/PerformanceMonitor.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/PerformanceMonitor.java index 082b27c75..f7a869e98 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/PerformanceMonitor.java +++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/PerformanceMonitor.java @@ -36,8 +36,12 @@ */ public class PerformanceMonitor { - private ScheduledExecutorService scheduler = - Executors.newScheduledThreadPool(1); + private ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1, runnable -> { + Thread thread = new Thread(runnable); + thread.setName("opennlp.tools.cmdline.PerformanceMonitor"); + thread.setDaemon(true); + return thread; + }); private final String unit; diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/GISTrainer.java b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/GISTrainer.java index e8f61774a..19d2c635e 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/GISTrainer.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/GISTrainer.java @@ -481,7 +481,14 @@ public GISModel trainModel(int iterations, DataIndexer di, Prior modelPrior, int /* Estimate and return the model parameters. */ private void findParameters(int iterations, double correctionConstant) { int threads = modelExpects.length; - ExecutorService executor = Executors.newFixedThreadPool(threads); + + ExecutorService executor = Executors.newFixedThreadPool(threads, runnable -> { + Thread thread = new Thread(runnable); + thread.setName("opennlp.tools.ml.maxent.ModelExpactationComputeTask.nextIteration()"); + thread.setDaemon(true); + return thread; + }); + CompletionService<ModelExpectationComputeTask> completionService = new ExecutorCompletionService<>(executor); double prevLL = 0.0; diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/quasinewton/ParallelNegLogLikelihood.java b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/quasinewton/ParallelNegLogLikelihood.java index 36cacb3ab..2429d001c 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/quasinewton/ParallelNegLogLikelihood.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/quasinewton/ParallelNegLogLikelihood.java @@ -104,7 +104,15 @@ public double valueAt(double[] x) { * Compute tasks in parallel */ private void computeInParallel(double[] x, Class<? extends ComputeTask> taskClass) { - ExecutorService executor = Executors.newFixedThreadPool(threads); + + ExecutorService executor = Executors.newFixedThreadPool(threads, runnable -> { + Thread thread = new Thread(runnable); + thread.setName( + "opennlp.tools.ml.maxent.quasinewton.ParallelNegLogLikelihood.computeInParallel()"); + thread.setDaemon(true); + return thread; + }); + int taskSize = numContexts / threads; int leftOver = numContexts % threads; ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Use Daemon threads in executor services > --------------------------------------- > > Key: OPENNLP-1224 > URL: https://issues.apache.org/jira/browse/OPENNLP-1224 > Project: OpenNLP > Issue Type: Improvement > Reporter: Edd Spencer > Assignee: Koji Sekiguchi > Priority: Major > > For all executor services it would be ideal if they are configured to use > daemon threads. This will mean that should the process need to be shutdown it > will not wait until these threads are complete in order to do so (which can > take a long time depending on operation). -- This message was sent by Atlassian JIRA (v7.6.3#76005)