Skip to content

Commit

Permalink
Use thread initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
niloc132 committed Dec 14, 2023
1 parent 06e5618 commit 5c25ad4
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.deephaven.util.SafeCloseable;
import io.deephaven.util.annotations.ScriptApi;
import io.deephaven.util.annotations.VisibleForTesting;
import io.deephaven.util.thread.NamingThreadFactory;
import io.deephaven.util.thread.ThreadInitializationFactory;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -96,7 +97,7 @@ public PythonDeephavenSession(
}
scriptFinder = new ScriptFinder(DEFAULT_SCRIPT_PATH);

registerJavaExecutor();
registerJavaExecutor(threadInitializationFactory);
publishInitial();
/*
* And now the user-defined initialization scripts, if any.
Expand Down Expand Up @@ -126,15 +127,21 @@ public PythonDeephavenSession(final UpdateGraph updateGraph,
}
scriptFinder = null;

registerJavaExecutor();
registerJavaExecutor(threadInitializationFactory);
publishInitial();
}

private void registerJavaExecutor() {
private void registerJavaExecutor(ThreadInitializationFactory threadInitializationFactory) {
// TODO (deephaven-core#4040) Temporary exec service until we have cleaner startup wiring
try (PyModule pyModule = PyModule.importModule("deephaven.server.executors");
final PythonDeephavenThreadsModule module = pyModule.createProxy(PythonDeephavenThreadsModule.class)) {
ExecutorService executorService = Executors.newFixedThreadPool(1);
NamingThreadFactory threadFactory = new NamingThreadFactory(PythonDeephavenSession.class, "serverThread") {
@Override
public Thread newThread(@NotNull Runnable r) {
return super.newThread(threadInitializationFactory.createInitializer(r));
}
};
ExecutorService executorService = Executors.newFixedThreadPool(1, threadFactory);
module._register_named_java_executor("serial", executorService::submit);
module._register_named_java_executor("concurrent", executorService::submit);
}
Expand Down

0 comments on commit 5c25ad4

Please sign in to comment.