java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.FutureTask@2a13d4e rejected from java.util.concurrent.ThreadPoolExecutor@1b2c3d4[Running, pool size = 200, active threads = 200, queued tasks = 0, completed tasks = 4500]
I am hitting this error repeatedly when trying to fetch user profiles using the Genesys Cloud Java SDK (genesys-cloud-platform-java). I am now trying to build a small Java service to sync some data. I assumed the SDK’s PlatformClientBuilder would handle connection pooling automatically like many other HTTP clients do.
Here is the basic setup I am using:
ApiClient client = PlatformClientBuilder.standard()
.withClientId("my-client-id")
.withClientSecret("my-client-secret")
.build(ApiClient.class);
UsersApi usersApi = new UsersApi(client);
// ... later in a loop
User user = usersApi.getUsersUserId("some-user-id").execute();
I am running this in a multi-threaded environment where I spawn about 50 concurrent threads to fetch user data. The application crashes with the RejectedExecutionException after a few hundred requests. I suspect the underlying HTTP client is not configured with a proper connection pool or is not thread-safe in the way I expected.
Since I am new to the Genesys Cloud provider ecosystem, I am not sure if I need to manually configure an OkHttpClient with a ConnectionPool and inject it into the ApiClient, or if there is a specific method on PlatformClientBuilder to tune this. I tried looking at the SDK source but it is quite dense. How should I configure the Java SDK to handle high concurrency without exhausting the thread pool? Do I need to create a shared ApiClient instance and ensure it is used across threads, or is each call creating a new underlying connection?
Thanks for the help.