apupier commented on code in PR #30711:
URL: https://github.com/apache/camel/pull/30711#discussion_r4682804835
##########
components/camel-ai/camel-semantic/src/main/java/org/apache/camel/semantic/SemanticEvaluateConsole.java:
##########
@@ -58,17 +64,41 @@ public class SemanticEvaluateConsole extends
AbstractDevConsole {
javaType = "java.lang.Long")
public static final String TIMEOUT = "timeout";
+ private final AtomicInteger active = new AtomicInteger();
private ExecutorService executor;
// A resolver-created console may be called without starting it; only an
explicit stop rejects calls.
- private boolean stopped;
+ private volatile boolean stopped;
+
+ private boolean tryAcquire() {
+ while (true) {
+ int count = active.get();
+ if (count >= 2) {
+ return false;
+ }
+ if (active.compareAndSet(count, count + 1)) {
+ return true;
+ }
+ }
+ }
+
+ private void release() {
+ active.decrementAndGet();
+ }
private synchronized ExecutorService executor() throws Exception {
if (stopped || isStopping()) {
throw new IllegalStateException("Semantic evaluation console is
stopping or stopped");
}
if (executor == null) {
- executor = new
ThreadPoolBuilder(getCamelContext()).poolSize(2).maxPoolSize(2).maxQueueSize(0)
-
.rejectedPolicy(ThreadPoolRejectedPolicy.Abort).build(this,
"SemanticEvaluation");
+ ThreadPoolProfile profile = new ThreadPoolProfile();
+ profile.setPoolSize(2);
+ profile.setMaxPoolSize(2);
+ profile.setMaxQueueSize(2);
+ profile.setAllowCoreThreadTimeOut(false);
+ profile.setKeepAliveTime(0L);
Review Comment:
Addressed: In `SemanticEvaluateConsole.doCallJson`, when `exec.submit()` is
rejected due to a transient permit wait race (e.g. while the previous virtual
thread is returning from `FutureTask.run()`), `submit()` is retried until
either submission succeeds or the request `deadline` is reached. If the
deadline expires while awaiting permit admission, it throws a
`TimeoutException` (producing a timeout failure response) rather than a false
`Busy` rejection. Additionally, if `task.get()` ever returns null, a fallback
timeout failure response is returned.
_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]