Java Platform SDK connection pooling and thread-safe HTTP client configuration

java.net.SocketException: Connection pool exhausted after 500 concurrent requests. I am configuring the Genesys Cloud Java Platform SDK for a high-throughput notification API gateway and the default OkHttpClient instance is failing under load. How do I properly inject a thread-safe connection pool configuration into the PureCloudPlatformClientV2 builder? My current setup uses PlatformClientBuilder.builder().withEnvironment(Environment.DEFAULT).withClientId(appId).withClientSecret(secret).build(), but I need to override the underlying HTTP client to enforce maxIdleConnections and connectionTimeouts without breaking OAuth token refresh cycles. Any working examples for explicit pool sizing?

The main issue here is that the default OkHttpClient in the Genesys Cloud Java SDK uses a shared static instance, which often causes Connection pool exhausted errors under high concurrency. While you can configure the builder, the real issue is usually not having a dedicated pool for high-throughput scenarios.

I faced similar 401 Unauthorized and timeout issues when scaling my OAuth refresh logic. Instead of fighting the default builder, I bypassed the high-level client for bulk operations and used the raw WebApiClient with a custom OkHttpClient instance.

OkHttpClient customClient = new OkHttpClient.Builder()
 .connectionPool(new ConnectionPool(200, 5, TimeUnit.MINUTES))
 .readTimeout(30, TimeUnit.SECONDS)
 .build();

WebApiClient webApi = new WebApiClient(customClient, Environment.DEFAULT);
pureCloudPlatformClient.setWebApiClient(webApi);

This gives you explicit control over ConnectionPool size and timeouts. Just ensure your withClientId and withClientSecret are still set on the main PlatformClient to handle the initial token generation before swapping the underlying HTTP client. Check your scope requirements too; admin:api often needs broader access than standard user tokens.