Signature overview
This topic describes how to implement OSS Java SDK timeout and retransmission, as well as code samples.
Details
- example of a function that timeout.
/** * to set the timeout period for establishing a connection. Unit: milliseconds. * @param connectionTimeout * The timeout period for establishing a connection (unit: milliseconds). */ public void setConnectionTimeout(int connectionTimeout) { this.connectionTimeout = connectionTimeout; } - Sample function for reconnection.
/** * to set a value that indicates the maximum number of retries after a retry request fails. (The default value is 3) * @param maxErrorRetry * The maximum number of retries after a retry request fails. */ public void setMaxErrorRetry(int maxErrorRetry) { this.maxErrorRetry = maxErrorRetry; } - The code for implementing timeout and reconnection is as follows. The timeout period set here is 5000 milliseconds and the number of retries is 3.
ClientConfiguration conf = new ClientConfiguration(); conf.setConnectionTimeout(5000); conf.setMaxErrorRetry(3); OSSClient(String endpoint, String accessKeyId, String accessKeySecret, ClientConfiguration config)
Applicable scope
- Object Storage Service (OSS)