From 7f3f45da34e7150ac9e998590256cb9f2f17e944 Mon Sep 17 00:00:00 2001 From: Caleb Hulbert Date: Tue, 12 Sep 2023 16:43:00 -0400 Subject: [PATCH] perf: dont use default executor, and only run single threaded --- .../control/navigation/ValueDisplayListener.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/janelia/saalfeldlab/paintera/control/navigation/ValueDisplayListener.java b/src/main/java/org/janelia/saalfeldlab/paintera/control/navigation/ValueDisplayListener.java index 978a8524b..2f7a5fd87 100644 --- a/src/main/java/org/janelia/saalfeldlab/paintera/control/navigation/ValueDisplayListener.java +++ b/src/main/java/org/janelia/saalfeldlab/paintera/control/navigation/ValueDisplayListener.java @@ -21,6 +21,8 @@ import java.util.HashMap; import java.util.Map; import java.util.Optional; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.function.Consumer; import java.util.function.Function; @@ -94,11 +96,13 @@ private static D getVal(final RealRandomAccess access, final ViewerPanelF private final Map, Task> taskMap = new HashMap<>(); + private final ExecutorService executor = Executors.newSingleThreadExecutor(); + private void getInfo() { final Optional> optionalSource = Optional.ofNullable(currentSource.getValue()); if (optionalSource.isPresent() && optionalSource.get() instanceof DataSource) { - final DataSource source = (DataSource)optionalSource.get(); + final DataSource source = (DataSource) optionalSource.get(); final var taskObj = Tasks.createTask(t -> { final ViewerState state = viewer.getState(); @@ -127,7 +131,7 @@ private void getInfo() { /* If we are creating a task for a source which has a running task, cancel the old task after removing. */ Optional.ofNullable(taskMap.put(source, taskObj)).ifPresent(Task::cancel); - taskObj.submit(); + taskObj.submit(executor); } } @@ -135,11 +139,11 @@ private void getInfo() { private static Function stringConverterFromSource(final DataSource source) { if (source instanceof ChannelDataSource) { - final long numChannels = ((ChannelDataSource)source).numChannels(); + final long numChannels = ((ChannelDataSource) source).numChannels(); // Cast not actually redundant //noinspection unchecked,RedundantCast - return (Function)(Function, String>)comp -> { + return (Function) (Function, String>) comp -> { StringBuilder sb = new StringBuilder("("); if (numChannels > 0) sb.append(comp.get(0).toString());