apupier commented on code in PR #30711:
URL: https://github.com/apache/camel/pull/30711#discussion_r4680572163


##########
components/camel-ai/camel-semantic/src/main/java/org/apache/camel/semantic/SemanticEvaluateConsole.java:
##########
@@ -125,12 +152,31 @@ protected Map<String, Object> doCallJson(Map<String, 
Object> options) {
         SemanticAuditService.Request request
                 = audit.request(options.containsKey(OPERATION) ? 
"direct_sample" : "definition_sample");
         String failure;
+        AtomicBoolean claimed = new AtomicBoolean();
+        boolean acquired = false;
         try {
             long timeout = optionLong(options, TIMEOUT, 50000);
             if (timeout < 1 || timeout > 50000) {
                 throw new IllegalArgumentException("Evaluation timeout must be 
between 1 and 50000 milliseconds");
             }
-            task = executor().submit(() -> evaluate(options, request));
+            if (stopped || isStopping()) {
+                throw new IllegalStateException("Semantic evaluation console 
is stopping or stopped");
+            }
+            if (!tryAcquire()) {
+                throw new RejectedExecutionException("Busy: semantic 
evaluations are already running");
+            }
+            acquired = true;
+            ExecutorService exec = executor();
+            task = exec.submit(() -> {

Review Comment:
   Addressed in edf6d03a: `deadline` is established at entry (`start + 
timeout`). The callable checks `System.nanoTime() > deadline` before executing 
`evaluate()` to prevent expired work from running, and `task.get()` waits on 
`remainingNanos` (`deadline - System.nanoTime()`), accounting for any 
submission delays.
   
   _IBM Bob on behalf of apupier_



-- 
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]

Reply via email to