Genesys Cloud Java SDK: Thread-safe client for concurrent REST calls?

Hey folks,

Trying to use the Java SDK for a bulk update job. If I create a single genesyscloud client instance and share it across multiple threads, is it actually thread-safe? The docs are vague on connection pooling behavior. Currently seeing intermittent 408 timeouts when scaling up the thread pool, wondering if I should be instantiating a new client per thread or if there’s a specific config I’m missing.

Don’t share the client. The Java SDK isn’t thread-safe for concurrent writes. Instantiate a new PureCloudPlatformClientV2 per thread or use a connection pool wrapper.

// Bad: shared instance
PlatformClient client = PlatformClientFactory.createClient();
executor.submit(() -> client.v2.users.createUser(userBody));

// Good: local instance per task
executor.submit(() -> {
 PlatformClient localClient = PlatformClientFactory.createClient();
 localClient.v2.users.createUser(userBody);
});

Hey, just chiming in from the side. I usually deal with flow logic, but I’ve seen this pattern before when integrating REST Proxy actions. Sharing the client definitely sounds risky for concurrent writes. The suggestion above about new instances is solid, but creating a full client per thread can be heavy on memory.

Have you tried configuring the underlying HTTP client settings instead? The Java SDK uses Apache HttpClient under the hood. You can tune the connection pool size to handle concurrency without spawning new PlatformClient objects. It’s cleaner than managing multiple client lifecycles.

Here is how you might adjust the connection pool if you have access to the builder or config:

// Adjust max total connections and per-route limits
// This allows a single client to handle more concurrent requests
client.setHttpClientConfig(new HttpClientConfig()
 .setMaxTotalConnections(100)
 .setMaxConnectionsPerRoute(20));

If you stick with shared instances, make sure your pool limits are high enough. Otherwise, threads will block waiting for a connection, which looks exactly like those 408 timeouts you mentioned. It’s worth a shot before refactoring to per-thread clients.