Authored by FengRuwei

添加线程池参数配置

... ... @@ -20,6 +20,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
... ... @@ -62,6 +63,13 @@ public class JavaApiClient {
JavaApiStatus javaApiStatus;
@Value("${JavaApiExecutorPoolCoreSize:20}")
private int JavaApiExecutorPoolCoreSize;
@Value("${JavaApiExecutorPoolMaxSize:50}")
private int JavaApiExecutorPoolMaxSize;
//TODO 需要 线程安全 处理 不过一般不会出现并发,任务周期比较长,一般周期内任务能够完成
private Map<String, JavaApiInfo> javaApimap;
... ... @@ -73,7 +81,8 @@ public class JavaApiClient {
public void initClient() {
executorService = new ThreadPoolExecutor(10, 30, 60, TimeUnit.SECONDS, new LinkedBlockingDeque<>(),
executorService = new ThreadPoolExecutor(JavaApiExecutorPoolCoreSize, JavaApiExecutorPoolMaxSize,
60, TimeUnit.SECONDS, new LinkedBlockingDeque<>(),
new JavaApiThreadFactory());
completionService = new ExecutorCompletionService<JavaApiStatics>(executorService);
... ...
... ... @@ -44,13 +44,15 @@ public class JavaApiTask implements Callable<JavaApiStatics> {
apiStatics.setHasException(false);
apiStatics.setJavaApiInfo(this.javaApiInfo);
apiStatics.setMObjectDetails(this.mObjectInfo);
//TODO JSON解析异常
try {
JSONObject req = null;
if (javaApiInfo.getApiData() != null && !(javaApiInfo.getApiData().equals("")))
req = JSON.parseObject(javaApiInfo.getApiData());
if (javaApiInfo.getApiReqMethod() == 0) {
JSONObject req = JSON.parseObject(javaApiInfo.getApiData());
jsonRep = restTemplate.getForObject(url, JSONObject.class);
} else {
JSONObject req = JSON.parseObject(javaApiInfo.getApiData());
jsonRep = restTemplate.postForObject(url, req, JSONObject.class);
}
... ...
... ... @@ -6,7 +6,7 @@
<bean id="javaapi_ConnectionManager" class="org.apache.http.impl.conn.PoolingHttpClientConnectionManager">
<property name="maxTotal" value="40" />
<property name="defaultMaxPerRoute" value="5" />
<property name="defaultMaxPerRoute" value="10" />
</bean>
<bean id="javaapi_httpClientBuilder" class="org.apache.http.impl.client.HttpClientBuilder"
... ... @@ -21,8 +21,8 @@
<bean id="javaapi_clientHttpRequestFactory"
class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory">
<constructor-arg ref="javaapi_httpClient" />
<property name="connectTimeout" value="2000" />
<property name="readTimeout" value="2000" />
<property name="connectTimeout" value="800" />
<property name="readTimeout" value="1200" />
</bean>
<bean id="javaapiRestTemplate" class="org.springframework.web.client.RestTemplate">
... ...
system.envi=product
\ No newline at end of file
system.envi=product
#java api 执行核心线程数
JavaApiExecutorPoolCoreSize=30
#java api 执行最大线程数
JavaApiExecutorPoolMaxSize=50
\ No newline at end of file
... ...
system.envi=test
\ No newline at end of file
system.envi=test
#java api 执行核心线程数
JavaApiExecutorPoolCoreSize=30
#java api 执行最大线程数
JavaApiExecutorPoolMaxSize=50
\ No newline at end of file
... ...