Configure connection timeout and retry behavior in the OSS Java SDK using ClientConfiguration.
Parameters
| Parameter | Method | Description | Default |
|---|---|---|---|
connectionTimeout | setConnectionTimeout(int) | Timeout for establishing a connection, in milliseconds | — |
maxErrorRetry | setMaxErrorRetry(int) | Maximum number of retries after a request fails | 3 |
Sample code
The following example sets a 5,000-millisecond connection timeout and a maximum of 3 retries, then passes the configuration when creating the client.
ClientConfiguration conf = new ClientConfiguration();
// Set the connection timeout to 5,000 milliseconds.
conf.setConnectionTimeout(5000);
// Set the maximum number of retries to 3.
conf.setMaxErrorRetry(3);
OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret, conf);Replace endpoint with your OSS endpoint URL, for example, https://oss-cn-hangzhou.aliyuncs.com.
The default value of maxErrorRetry is 3. Increase this value if your application needs to tolerate more transient network errors.