我正在运行一个 Spring启动应用程序,它创建 200个线程,调用 API 调用另一个REST服务。
问题是,一旦我启动方法启动该过程,CPU利用率%就会超过 350%。我使用ThreadPoolExecutor, ThreadPoolTaskExecutor AsyncTaskExecutor
来管理AsyncRestTemplate
的API调用,但这没有任何区别。
控制器
@RequestMapping(method = RequestMethod.GET)
public String main(){
//executor.submit(coins_);
AsyncTaskExecutor threadpoolExtractor = appCtx.getBean(AsyncTaskExecutor.class);
asyncRestTemplate = new AsyncRestTemplate((AsyncListenableTaskExecutor) threadpoolExtractor);
}
来自另一个类的 Get
方法。
public String GET(String desiredUrl, AsyncRestTemplate asyncRestTemplate) {
String response;
try {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
response = asyncRestTemplate.exchange(desiredUrl, HttpMethod.GET, new HttpEntity<>("result", headers), String.class).get().getBody();
return response;
} catch (InterruptedException | ExecutionException ex) {
Logger.getLogger(HTTP_Methods.class.getName()).log(Level.SEVERE, null, ex);
ex.printStackTrace();
}
return null;
}