diff --git a/src/main/java/org/janelia/saalfeldlab/fx/ortho/OrthogonalViews.java b/src/main/java/org/janelia/saalfeldlab/fx/ortho/OrthogonalViews.java index fed10358e..c8f1035e4 100644 --- a/src/main/java/org/janelia/saalfeldlab/fx/ortho/OrthogonalViews.java +++ b/src/main/java/org/janelia/saalfeldlab/fx/ortho/OrthogonalViews.java @@ -146,6 +146,7 @@ public OrthogonalViews( final ForkJoinPool.ForkJoinWorkerThreadFactory factory = pool -> { final ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool); + worker.setPriority(4); worker.setName("render-thread-" + worker.getPoolIndex()); return worker; }; diff --git a/src/main/java/org/janelia/saalfeldlab/paintera/control/paint/FloodFill2D.java b/src/main/java/org/janelia/saalfeldlab/paintera/control/paint/FloodFill2D.java index 4e1e9111b..c42cc1424 100644 --- a/src/main/java/org/janelia/saalfeldlab/paintera/control/paint/FloodFill2D.java +++ b/src/main/java/org/janelia/saalfeldlab/paintera/control/paint/FloodFill2D.java @@ -37,6 +37,7 @@ import org.janelia.saalfeldlab.paintera.data.mask.MaskedSource; import org.janelia.saalfeldlab.paintera.data.mask.SourceMask; import org.janelia.saalfeldlab.paintera.data.mask.exception.MaskInUse; +import org.janelia.saalfeldlab.util.NamedThreadFactory; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; @@ -45,6 +46,8 @@ import java.lang.invoke.MethodHandles; import java.util.Arrays; import java.util.Objects; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.function.BooleanSupplier; import java.util.function.Predicate; @@ -156,6 +159,12 @@ public UtilityTask fillViewerAt(final double currentViewerX, final dou return fillMaskAt(maskPos, mask, fill, filter); } + private ExecutorService floodFillExector = newFloodFillExecutor(); + + private ExecutorService newFloodFillExecutor() { + return Executors.newSingleThreadExecutor(new NamedThreadFactory("flood-fill-2d", false, 8)); + } + @NotNull private UtilityTask fillMaskAt(Point maskPos, ViewerMask mask, Long fill, RandomAccessibleInterval filter) { @@ -181,8 +190,11 @@ private UtilityTask fillMaskAt(Point maskPos, ViewerMask mask, Long fi }); }); - floodFillTask.submit(); + if (floodFillExector.isShutdown()) { + floodFillExector = newFloodFillExecutor(); + } + floodFillTask.submit(floodFillExector); refreshDuringFloodFill(floodFillTask).start(); return floodFillTask; } @@ -264,7 +276,7 @@ public static Thread refreshDuringFloodFill() { public static Thread refreshDuringFloodFill(Task task) { - return new Thread(() -> { + final Thread refreshScreenThread = new Thread(() -> { while (task == null || !task.isDone()) { try { Thread.sleep(100); @@ -283,6 +295,8 @@ public static Thread refreshDuringFloodFill(Task task) { task.cancel(); } }); + refreshScreenThread.setPriority(2); + return refreshScreenThread; } /**