From 09a5f99059226ea4b56bc77d84b272d852e011a4 Mon Sep 17 00:00:00 2001
From: Jose <jose@zeroc.com>
Date: Thu, 26 Dec 2024 12:08:53 +0100
Subject: [PATCH] Executor service fixes

---
 .../src/main/java/com/zeroc/Ice/Instance.java | 10 ++++++---
 .../com/zeroc/Ice/QueueExecutorService.java   | 22 -------------------
 2 files changed, 7 insertions(+), 25 deletions(-)

diff --git a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/Instance.java b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/Instance.java
index 12636456fa9..1dd441aaaf4 100644
--- a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/Instance.java
+++ b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/Instance.java
@@ -82,15 +82,19 @@ protected void afterExecute(Runnable t, Throwable e) {
         private final ThreadObserverHelper _observerHelper;
     }
 
+    // The thead pool executor uses an unbounded queue. The tasks would wait in the queue until a
+    // core pool thread is available to run it and the value of the maximumPoolSize therefore
+    // doesn't have any effect.
     private static class QueueExecutor extends java.util.concurrent.ThreadPoolExecutor {
         QueueExecutor(Properties props, String threadName) {
             super(
-                    1,
-                    1,
-                    0,
+                    10,
+                    10,
+                    1000,
                     TimeUnit.MILLISECONDS,
                     new java.util.concurrent.LinkedBlockingQueue<Runnable>(),
                     Util.createThreadFactory(props, threadName));
+            allowCoreThreadTimeOut(true);
             _observerHelper = new ThreadObserverHelper(threadName);
         }
 
diff --git a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/QueueExecutorService.java b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/QueueExecutorService.java
index d0588c3dc6d..0a85ec7ed32 100644
--- a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/QueueExecutorService.java
+++ b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/QueueExecutorService.java
@@ -13,14 +13,6 @@
 final class QueueExecutorService {
     QueueExecutorService(ExecutorService executor) {
         _executor = executor;
-        _thread =
-                executeNoThrow(
-                        new Callable<Thread>() {
-                            @Override
-                            public Thread call() {
-                                return Thread.currentThread();
-                            }
-                        });
     }
 
     public <T> T executeNoThrow(Callable<T> callable) {
@@ -33,19 +25,6 @@ public <T> T executeNoThrow(Callable<T> callable) {
     }
 
     public <T> T execute(Callable<T> callable) throws RetryException {
-        if (_thread == Thread.currentThread()) {
-            try {
-                return callable.call();
-            } catch (RuntimeException ex) {
-                throw ex;
-            } catch (Exception ex) {
-                // RetryException is the only checked exception that
-                // can be raised by Ice internals.
-                assert (ex instanceof RetryException);
-                throw (RetryException) ex;
-            }
-        }
-
         boolean interrupted = false;
         try {
             Future<T> future = _executor.submit(callable);
@@ -78,5 +57,4 @@ public <T> T execute(Callable<T> callable) throws RetryException {
     }
 
     final ExecutorService _executor;
-    final Thread _thread;
 }