Repository navigation
Conversation
…or is stopped Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
|
Add Carrot credits or activate Agent usage billing to use Autofix |
There was a problem hiding this comment.
🟡 Changes recommended
Interrupting the last non-daemon thread before shutdown completes can let the JVM exit early, abandoning controller shutdown, reconciliation draining, or client cleanup.
1 open issue
What changed in this PR
Adds opt-in JVM lifetime management through Operator.keepAlive(), separating it from executor behavior and supporting operators that use only daemon threads.
Changes:
- Adds a non-daemon keep-alive thread with stop and restart handling.
- Adds tests for thread lifecycle, repeated calls, and opt-in behavior.
- Documents the API with a startup example.
| File | Description |
|---|---|
operator-framework-core/src/test/java/io/javaoperatorsdk/operator/OperatorKeepAliveTest.java |
Tests keep-alive thread behavior and lifecycle. |
operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java |
Adds keepAlive() and integrates thread termination with stop(). |
docs/content/en/docs/documentation/operations/configuration.md |
Explains when and how to keep the JVM alive. |
Review effort: Balanced
| */ | ||
| @Override | ||
| public void stop() throws OperatorException { | ||
| stopKeepAlive(); |

Summary
Adds
Operator.keepAlive(), which starts a non-daemon thread that keeps the JVM running until the operator is stopped.The operator normally keeps the JVM alive through the non-daemon threads of its thread pools. When nothing else does, for example when all the threads of the operator are daemon threads as is the case with virtual threads, the JVM exits as soon as the
mainmethod returns after starting the operator. This makes keeping the JVM alive an explicit, on demand choice instead of a side effect of the executors.Extracted from the virtual thread support PR (#3664), where the same thread used to be started by the
ExecutorServiceManager.Behavior
start().stop()ends the thread, including when the operator was never started, so it works together withinstallShutdownHook().keepAlive()can be called again after a stop.keepAlive()is called.Documentation
New "Keeping the JVM Alive" section in
operations/configuration.md.Tests
OperatorKeepAliveTest:stop()