Java AsyncRestTemplate配置队列大小
我有一个每小时运行一次的作业,在40core服务器上,每个作业可以有1到10万个任务(需要大队列),每个任务完成后执行HTTP请求,每个任务都是关键的,这意味着它必须运行并完成 任务可以异步运行 如何配置池中的线程数?如何配置队列大小 在这个测试中,我试图让我的任务被拒绝并淹没我的线程池,但我得到的却是SocketTimeoutExceptionJava AsyncRestTemplate配置队列大小,java,spring,multithreading,asynchronous,Java,Spring,Multithreading,Asynchronous,我有一个每小时运行一次的作业,在40core服务器上,每个作业可以有1到10万个任务(需要大队列),每个任务完成后执行HTTP请求,每个任务都是关键的,这意味着它必须运行并完成 任务可以异步运行 如何配置池中的线程数?如何配置队列大小 在这个测试中,我试图让我的任务被拒绝并淹没我的线程池,但我得到的却是SocketTimeoutException public static void main(String[] args) throws IOReactorException { Stri
public static void main(String[] args) throws IOReactorException {
String url = "http://internal.server:8001/get";
int connectionTimeout = 3000;
int soTimeout = 3000;
int maxHttpConnections = 30;
IOReactorConfig customIOReactorConfig = IOReactorConfig.custom()
.setIoThreadCount(Runtime.getRuntime().availableProcessors())
.setConnectTimeout(connectionTimeout)
.setSoTimeout(soTimeout)
.build();
ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(customIOReactorConfig);
PoolingNHttpClientConnectionManager connManager = new PoolingNHttpClientConnectionManager(ioReactor);
connManager.setDefaultMaxPerRoute(maxHttpConnections);
connManager.setMaxTotal(maxHttpConnections);
CloseableHttpAsyncClient customHttpAsyncClient = HttpAsyncClients.custom()
.setConnectionManager(connManager)
.build();
HttpComponentsAsyncClientHttpRequestFactory asyncRequestFactory = new HttpComponentsAsyncClientHttpRequestFactory(customHttpAsyncClient);
AsyncRestTemplate asyncRestTemplate = new AsyncRestTemplate(asyncRequestFactory);
System.out.println("start");
for (int i = 0; i < 30_000; i++) {
asyncRestTemplate.execute(url, HttpMethod.GET, request -> logger.info("doWithRequest..."), response -> {
logger.info("extractData...");
return response.getStatusText();
}).addCallback(new ListenableFutureCallback<String>() {
@Override
public void onFailure(Throwable ex) {
logger.error("onFailure [{}] [{}]", ex.getMessage(), ex.getStackTrace()[0].toString());
}
@Override
public void onSuccess(String result) {
logger.info("onSuccess");
}
});
}
System.out.println("end loop");
}
publicstaticvoidmain(字符串[]args)抛出IOreactoreException{
字符串url=”http://internal.server:8001/get";
int connectionTimeout=3000;
int-soTimeout=3000;
int maxHttpConnections=30;
IOReactorConfig customIOReactorConfig=IOReactorConfig.custom()
.setIoThreadCount(Runtime.getRuntime().availableProcessors())
.setConnectTimeout(connectionTimeout)
.setSoTimeout(soTimeout)
.build();
ConnectionReactor ioReactor=新的默认ConnectionReactor(customIOReactorConfig);
PoolingHttpClientConnectionManager connManager=新的PoolingHttpClientConnectionManager(ioReactor);
connManager.setDefaultMaxPerRoute(maxHttpConnections);
connManager.setMaxTotal(maxHttpConnections);
CloseableHttpAsyncClient customHttpAsyncClient=HttpAsyncClient.custom()
.setConnectionManager(连接管理器)
.build();
HttpComponentsAsyncClientHttpRequestFactory asyncRequestFactory=新HttpComponentsAsyncClientHttpRequestFactory(customHttpAsyncClient);
AsyncRestTemplate AsyncRestTemplate=新的AsyncRestTemplate(asyncRequestFactory);
系统输出打印项次(“开始”);
对于(int i=0;i<30_000;i++){
asyncRestTemplate.execute(url,HttpMethod.GET,请求->记录器.info(“doWithRequest…”),响应->{
logger.info(“提取数据…”);
返回response.getStatusText();
}).addCallback(新ListenableFutureCallback(){
@凌驾
失效时的公共无效(可丢弃的ex){
logger.error(“onFailure[{}][{}]”,例如getMessage(),例如getStackTrace()[0].toString());
}
@凌驾
成功时的公共void(字符串结果){
logger.info(“onSuccess”);
}
});
}
System.out.println(“结束循环”);
}