Skip to content

Commit

Permalink
named, daemonised and applied fix as suggested in #36
Browse files Browse the repository at this point in the history
some unknown 'ForkJoinPool.commonPool-worker-' remaining
  • Loading branch information
RalphSteinhagen committed Sep 18, 2019
1 parent 46a7776 commit e8aa9ff
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 37 deletions.
Expand Up @@ -17,6 +17,7 @@
import de.gsi.dataset.DataSet;
import de.gsi.dataset.DataSetError;
import de.gsi.dataset.DataSetError.ErrorType;
import de.gsi.dataset.utils.CachedDaemonThreadFactory;
import de.gsi.dataset.utils.ProcessingProfiler;
import de.gsi.math.ArrayUtils;

Expand All @@ -38,7 +39,8 @@ class CachedDataPoints {
private static final String X_VALUES = "xValues";
private static final double DEG_TO_RAD = Math.PI / 180.0;
private static final int MAX_THREADS = Math.max(4, Runtime.getRuntime().availableProcessors());
private static final ExecutorService EXECUTOR_SERVICE = Executors.newFixedThreadPool(2 * MAX_THREADS);
private static final ExecutorService EXECUTOR_SERVICE = Executors.newFixedThreadPool(2 * MAX_THREADS,
CachedDaemonThreadFactory.getInstance());

protected double[] xValues;
protected double[] yValues;
Expand Down
Expand Up @@ -9,6 +9,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import de.gsi.dataset.utils.CachedDaemonThreadFactory;
import de.gsi.dataset.utils.ProcessingProfiler;

/**
Expand All @@ -18,7 +19,7 @@
* </p>
*/
public class MarchingSquares {
private static final ExecutorService ES = Executors.newCachedThreadPool();
private static final ExecutorService ES = Executors.newCachedThreadPool(CachedDaemonThreadFactory.getInstance());
private double[] isovalues;

private static Grid contour(final double[][] data, final double isovalue) {
Expand Down Expand Up @@ -71,40 +72,40 @@ private static Grid contour(final double[][] data, final double isovalue) {
float bottom = 0.5F;
switch (ndx) {
case 1:
case 14:
left = (float) ((isovalue - bl) / (tl - bl));
case 14:
left = (float) ((isovalue - bl) / (tl - bl));
bottom = (float) ((isovalue - bl) / (br - bl));
break;
case 2:
case 13:
bottom = (float) ((isovalue - bl) / (br - bl));
case 13:
bottom = (float) ((isovalue - bl) / (br - bl));
right = (float) ((isovalue - br) / (tr - br));
break;
case 3:
case 12:
left = (float) ((isovalue - bl) / (tl - bl));
case 12:
left = (float) ((isovalue - bl) / (tl - bl));
right = (float) ((isovalue - br) / (tr - br));
break;
case 4:
case 11:
top = (float) ((isovalue - tl) / (tr - tl));
case 11:
top = (float) ((isovalue - tl) / (tr - tl));
right = (float) ((isovalue - br) / (tr - br));
break;
case 5:
case 10:
left = (float) ((isovalue - bl) / (tl - bl));
case 10:
left = (float) ((isovalue - bl) / (tl - bl));
bottom = (float) ((isovalue - bl) / (br - bl));
top = (float) ((isovalue - tl) / (tr - tl));
right = (float) ((isovalue - br) / (tr - br));
break;
case 6:
case 9:
bottom = (float) ((isovalue - bl) / (br - bl));
case 9:
bottom = (float) ((isovalue - bl) / (br - bl));
top = (float) ((isovalue - tl) / (tr - tl));
break;
case 7:
case 8:
left = (float) ((isovalue - bl) / (tl - bl));
case 8:
left = (float) ((isovalue - bl) / (tl - bl));
top = (float) ((isovalue - tl) / (tr - tl));
break;
default: // shouldn't happen
Expand Down
Expand Up @@ -3,25 +3,27 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import de.gsi.dataset.utils.CachedDaemonThreadFactory;

/**
* @author rstein
*
*/
public class EventThreadHelper {
private static final int MAX_THREADS = Math.max(4, Runtime.getRuntime().availableProcessors());
private static final ExecutorService EXECUTOR_SERVICE = Executors.newFixedThreadPool(2 * MAX_THREADS);

/**
* @return maximum number of threads used for event notification
*/
public static int getMaxThreads() {
return MAX_THREADS;
}

/**
* @return event update executor service
*/
public static ExecutorService getExecutorService() {
return EXECUTOR_SERVICE;
}
private static final int MAX_THREADS = Math.max(4, Runtime.getRuntime().availableProcessors());
private static final ExecutorService EXECUTOR_SERVICE = Executors.newFixedThreadPool(2 * MAX_THREADS,
CachedDaemonThreadFactory.getInstance());

/**
* @return maximum number of threads used for event notification
*/
public static int getMaxThreads() {
return MAX_THREADS;
}

/**
* @return event update executor service
*/
public static ExecutorService getExecutorService() {
return EXECUTOR_SERVICE;
}
}
@@ -0,0 +1,27 @@
package de.gsi.dataset.utils;

import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;

public class CachedDaemonThreadFactory implements ThreadFactory {
private static final ThreadFactory defaultFactory = Executors.defaultThreadFactory();
private static final CachedDaemonThreadFactory SELF = new CachedDaemonThreadFactory();
private static int threadCounter = 1;

private CachedDaemonThreadFactory() {
// helper class
}

public static CachedDaemonThreadFactory getInstance() {
return SELF;
}

@Override
public Thread newThread(Runnable r) {
Thread thread = defaultFactory.newThread(r);
thread.setName("daemonised_chartfx_thread_#" + threadCounter);
threadCounter++;
thread.setDaemon(true);
return thread;
}
}
Expand Up @@ -58,21 +58,27 @@ public class ConcurrencyUtils {
private static int forceNThreads = 1;

private static class CustomExceptionHandler implements Thread.UncaughtExceptionHandler {
public void uncaughtException(Thread t, Throwable e) {
@Override
public void uncaughtException(Thread t, Throwable e) {
e.printStackTrace();
}
}

private static class CustomThreadFactory implements ThreadFactory {
private static final ThreadFactory defaultFactory = Executors.defaultThreadFactory();
private final Thread.UncaughtExceptionHandler handler;

private static int threadCounter = 1;

CustomThreadFactory(Thread.UncaughtExceptionHandler handler) {
this.handler = handler;
}

public Thread newThread(Runnable r) {
@Override
public Thread newThread(Runnable r) {
Thread t = defaultFactory.newThread(r);
t.setDaemon(true);
t.setName("daemonised_chartfx_math_thread"+threadCounter);
threadCounter++;
t.setUncaughtExceptionHandler(handler);
return t;
}
Expand Down
Expand Up @@ -20,6 +20,7 @@
import de.gsi.dataset.testdata.spi.RandomDataGenerator;
import de.gsi.dataset.utils.ProcessingProfiler;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
Expand Down Expand Up @@ -100,7 +101,7 @@ public void start(final Stage primaryStage) {
startTime = ProcessingProfiler.getTimeStamp();
primaryStage.setTitle(this.getClass().getSimpleName());
primaryStage.setScene(scene);
primaryStage.setOnCloseRequest(evt -> System.exit(0));
primaryStage.setOnCloseRequest(evt -> Platform.exit());
primaryStage.show();
ProcessingProfiler.getTimeDiff(startTime, "for showing");

Expand Down

0 comments on commit e8aa9ff

Please sign in to comment.