Is the ApiClient instance in the Genesys Cloud Java SDK actually thread-safe for concurrent use across multiple worker threads, or do I need to instantiate a new client per thread?
I’m running a high-throughput batch process that polls /api/v2/users and updates routing profiles. The current setup uses a single static ApiClient initialized at startup.
ApiClient client = ApiClient.builder()
.withBaseUri("https://api.mypurecloud.com")
.withAuthMethod(new OAuthClientCredentials(...))
.build();
// Used by 50 concurrent threads
CompletableFuture.runAsync(() -> {
UsersApi usersApi = new UsersApi(client);
// fetch users...
}, executorService);
Under load, I’m seeing intermittent java.net.SocketTimeoutException: Read timed out and occasionally javax.net.ssl.SSLException: Connection has been shutdown. The underlying HTTP client is Apache HttpClient 4.x.
The SDK docs are vague on whether the internal CloseableHttpClient is configured for concurrent access. I suspect the connection pool is getting exhausted or corrupted because the default PoolingHttpClientConnectionManager might not be handling the simultaneous requests correctly with the default timeouts.
I’ve tried increasing the max connections per route, but the errors persist. Should I be creating a new ApiClient for each thread, or is there a specific configuration flag I’m missing to make the shared instance safe? The performance hit of creating new clients per request is unacceptable for this volume. Need to know if this is a known limitation or a config issue.