This topic describes how to configure an HTTP connection pool in Alibaba Cloud SDK V1.0.
When you initialize an SDK client in SDK V1.0, you can use HttpClientConfig to configure an HTTP connection pool. The HTTP connection pool processes API requests that are initiated from SDKs for multiple Alibaba Cloud services because you can use only one SDK client.
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.http.HttpClientConfig;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;
public class Sample {
public static void main(String[] args) {
// Create a DefaultAcsClient instance and initialize the instance.
DefaultProfile profile = DefaultProfile.getProfile(
// The ID of the region.
"<region-id>",
// Obtain the AccessKey ID of the Resource Access Management (RAM) user from environment variables.
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
// Obtain the AccessKey secret of the RAM user from environment variables.
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
/* The parameters for the HTTP connection pool that is used by multiple SDK clients. For example, you can configure the maximum number of connections of each host and the timeout period. */
HttpClientConfig clientConfig = HttpClientConfig.getDefault();
clientConfig.setMaxRequestsPerHost(6);
// Unit: millisecond.
clientConfig.setConnectionTimeoutMillis(30000L);
clientConfig.setMaxIdleConnections(20);
profile.setHttpClientConfig(clientConfig);
IAcsClient client = new DefaultAcsClient(profile);
}
}