Hey everyone,
I’ve been running into a weird issue with our WFM adherence checker script. It works fine when I run it locally on my machine, but as soon as I deploy it to our server in Chicago, it starts timing out after about 20 requests.
We’re using the Java Platform SDK. I’m trying to configure the ClientBuilder to use a connection pool so it doesn’t open a new TCP connection for every single API call. The idea is to keep connections open to save time.
Here is the code I’m using to set up the client:
import com.mypurecloud.api.client.ApiException;
import com.mypurecloud.api.client.ClientBuilder;
import org.apache.http.impl.client.BasicCredentialsProvider;
// ... inside my service class
private ClientBuilder buildClient() {
ClientBuilder builder = new ClientBuilder();
builder.setClientId("my-client-id");
builder.setClientSecret("my-client-secret");
builder.setEnvironment("mypurecloud.com");
// Attempting to configure connection pooling
// I found this method in the docs but I'm not sure if it's correct
builder.setMaxConnections(50);
builder.setMaxConnectionsPerRoute(20);
return builder;
}
The error I get is:
com.mypurecloud.api.client.ApiException: java.net.SocketTimeoutException: Connect timed out
at com.mypurecloud.api.client.ApiClient.execute(ApiClient.java:455)
...
It happens randomly. Sometimes it works, sometimes it doesn’t. I’m thinking maybe the thread safety is off? Or maybe I’m setting the pool size wrong?
I’m a beginner with Java networking stuff, so I’m not sure what the right way to handle this is. Does the SDK handle thread safety automatically? Or do I need to use a specific HTTP client implementation?
Any help would be great. I just need this to run stable for our 24-hour adherence reports.