Skip to content

Workflow streams user publish executor - #3025

Open
diwu-sf wants to merge 3 commits into
temporalio:mainfrom
diwu-sf:workflow-streams-user-publish-executor
Open

Workflow streams user publish executor#3025
diwu-sf wants to merge 3 commits into
temporalio:mainfrom
diwu-sf:workflow-streams-user-publish-executor

Conversation

@diwu-sf

@diwu-sf diwu-sf commented Aug 20, 2026

Copy link
Copy Markdown

What was changed

Every StreamPublisher instance was creating its own single thread executor to run the background flush. If the worker has high concurrency and many publishers, more and more platform threads will be created (and these mostly just idle).

When using virtual threads, it's also not possible to override this executor with a shared one that uses virtual threads. Follow the pattern from workflow stream client and allow configuring a shared publish executor.

Why?

To reduce the number of idle platform threads created for each stream publisher instance.

Checklist

  1. Closes
  1. How was this tested:

Tests added

  1. Any docs updates needed?

Doc updated

StreamPublisher always created its own native platform thread executor
to drive the background flush loop, one thread per publisher, with no
way to share an executor across publishers. Applications that want to
run flushes on virtual threads or a shared pool had no way to opt in.

Add a constructor that accepts a ScheduledExecutorService. When one is
supplied, the publisher never shuts it down: it only cancels the
periodic flush task on close or on a deferred flush timeout, leaving
the executor free for its other work. The default (no executor)
behavior is unchanged: a lazily created single-thread executor owned
and shut down by the publisher.
Every WorkflowStreamClient paid a dedicated platform thread for its
publisher's flush loop, with no way to share an executor across clients
even though WorkflowStreamClientOptions already allows one for the poll
path. Applications that want virtual threads or one shared pool for
many clients had no way to opt in.

Add setPublishExecutor, mirroring setPollExecutor: the supplied executor
drives the background flushes and the client never shuts it down — on
close it only stops its own tasks. Default behavior is unchanged.
Document the option in the module README and cover it with an
integration test sharing one executor across two clients.
Mentioning virtual threads ties the docs to the newest JDKs even though
any shared ScheduledExecutorService works. Describe the option in terms
of sharing one executor across clients instead.
@diwu-sf
diwu-sf requested review from a team as code owners August 20, 2026 22:45
@CLAassistant

CLAassistant commented Aug 20, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants