WANG 6 tahun lalu
induk
melakukan
97aa40aaaa

+ 9 - 5
examcloud-exchange-inner-service/src/main/java/cn/com/qmth/examcloud/exchange/inner/service/upyun/UpYunClient.java

@@ -20,6 +20,7 @@ import org.apache.http.client.methods.HttpPut;
 import org.apache.http.entity.InputStreamEntity;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClients;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
 import org.apache.http.util.EntityUtils;
 
 import com.upyun.UpException;
@@ -82,8 +83,10 @@ public class UpYunClient {
 	 * @param password
 	 */
 	public UpYunClient(String bucketName, String userName, String password) {
-
-		httpclient = HttpClients.custom().disableAutomaticRetries().build();;
+		PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
+		cm.setMaxTotal(1000);
+		httpclient = HttpClients.custom().setConnectionManager(cm).disableAutomaticRetries()
+				.build();
 		requestConfig = RequestConfig.custom().setConnectionRequestTimeout(10000)
 				.setSocketTimeout(10000).setConnectTimeout(10000).build();
 
@@ -128,7 +131,7 @@ public class UpYunClient {
 
 		HttpPut httpPut = new HttpPut(url);
 		httpPut.setConfig(this.requestConfig);
-
+		CloseableHttpResponse response = null;
 		try {
 			String date = getGMTDate();
 			httpPut.addHeader(DATE, date);
@@ -139,7 +142,7 @@ public class UpYunClient {
 			httpPut.addHeader(MKDIR, "true");
 
 			httpPut.setEntity(new InputStreamEntity(in));
-			CloseableHttpResponse response = httpclient.execute(httpPut);
+			response = httpclient.execute(httpPut);
 			int statusCode = response.getStatusLine().getStatusCode();
 
 			if (HttpStatus.SC_OK != statusCode) {
@@ -153,8 +156,9 @@ public class UpYunClient {
 		} catch (Exception e) {
 			throw new ExamCloudRuntimeException(e);
 		} finally {
-			httpPut.releaseConnection();
 			IOUtils.closeQuietly(in);
+			IOUtils.closeQuietly(response);
+			httpPut.releaseConnection();
 		}
 
 		String fileUrl = "http://" + bucketName + ".b0.upaiyun.com" + filePath;