我必须修改dropwizard应用程序以改善其运行时间.基本上,该应用程序每天接收大约300万个URL并下载并解析它们以检测恶意内容.问题是该应用程序只能处理100万个URL.当我查看应用程序时,我发现它正在进行大量的顺序调用.我想了解如何通过使其成为异步或其他技术来改进应用程序.
所需代码如下: -
/* Scheduler */
private long triggerDetection(String startDate, String endDate) {
for (UrlRequest request : urlRequests) {
if (!validateRequests.isWhitelisted(request)) {
ContentDetectionClient.detectContent(request);
}
}
}
/* Client */
public void detectContent(UrlRequest urlRequest){
Client client = new Client();
URI uri = buildUrl(); /* It returns the URL of this dropwizard application's resource method provided below */
ClientResponse response = client.resource(uri)
.type(MediaType.APPLICATION_JSON_TYPE)
.post(ClientResponse.class, urlRequest);
Integer status = response.getStatus();
if (status >= 200 && status < 300) {
log.info("Completed request for url: …Run Code Online (Sandbox Code Playgroud)