Skip to content

Commit

Permalink
perf: dont use default executor, and only run single threaded
Browse files Browse the repository at this point in the history
  • Loading branch information
cmhulbert committed Sep 12, 2023
1 parent ed2ca94 commit 7f3f45d
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -94,11 +96,13 @@ private static <D> D getVal(final RealRandomAccess<D> access, final ViewerPanelF

private final Map<DataSource<?, ?>, Task<?>> taskMap = new HashMap<>();

private final ExecutorService executor = Executors.newSingleThreadExecutor();

private <D> void getInfo() {

final Optional<Source<?>> optionalSource = Optional.ofNullable(currentSource.getValue());
if (optionalSource.isPresent() && optionalSource.get() instanceof DataSource<?, ?>) {
final DataSource<D, ?> source = (DataSource<D, ?>)optionalSource.get();
final DataSource<D, ?> source = (DataSource<D, ?>) optionalSource.get();

final var taskObj = Tasks.<String>createTask(t -> {
final ViewerState state = viewer.getState();
Expand Down Expand Up @@ -127,19 +131,19 @@ private <D> 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);

}
}

private static <D> Function<D, String> stringConverterFromSource(final DataSource<D, ?> 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<D, String>)(Function<? extends Composite<?>, String>)comp -> {
return (Function<D, String>) (Function<? extends Composite<?>, String>) comp -> {
StringBuilder sb = new StringBuilder("(");
if (numChannels > 0)
sb.append(comp.get(0).toString());
Expand Down

0 comments on commit 7f3f45d

Please sign in to comment.