imbajin commented on code in PR #2941:
URL:
https://github.com/apache/incubator-hugegraph/pull/2941#discussion_r2716452425
##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/util/Consumers.java:
##########
@@ -104,9 +104,23 @@ public void start(String name) {
LOG.info("Starting {} workers[{}] with queue size {}...",
this.workers, name, this.queueSize);
for (int i = 0; i < this.workers; i++) {
- this.runningFutures.add(
- this.executor.submit(new
ContextCallable<>(this::runAndDone)));
+ this.runningFutures.add(this.executor.submit(this::safeRun));
}
+
+ }
+ private Void safeRun() {
+ try {
+ new ContextCallable<>(this::runAndDone).call();
Review Comment:
> would it be alright to just implement ContextCallable wraps safeRun in
start() , so the context is captured at submission time and safeRun() simply
calls runAndDone() and always decrements the latch in a finally block?
Sure, the execution Flow may like:
```
Submission Thread: start()
→ new ContextCallable<>(this::safeRun) // ✅ Captures context here
→ executor.submit(...)
→ Worker Thread: ContextCallable.call()
→ setContext(captured_context) // ✅ Sets submission thread's context
→ safeRun()
→ runAndDone()
→ latch.countDown() // ✅ Always executes
→ resetContext()
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]