[英]Spring-Boot: Handle multiple requests concurrently
I am using Spring Boot to build a RESTful web service . 我正在使用Spring Boot构建RESTful Web服务 。 My IDE is Eclipse Oxygen.
我的IDE是Eclipse Oxygen。
I send multiple HTTP get requests in every 2 seconds through Chrome , but they are triggered one by one . 我每2秒通过Chrome发送多个 HTTP get请求,但它们是一个接一个地触发的 。 Each request will wait for the previous request to finish.
每个请求将等待上一个请求完成。
Here is my controller code: 这是我的控制器代码:
@RestController
@RequestMapping("/dummy")
public class DummyController {
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<Map<String, String>> dummytsp(@RequestParam(value="msg", defaultValue="Hello") String msg) {
System.out.println("" + new Date() + ": ThreadId " + Thread.currentThread().getId());
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Map<String, String> response = new HashMap<>();
response.put("message", msg);
return new ResponseEntity<>(response, HttpStatus.OK);
}
}
My console out put is: 我的控制台输出是:
Thu Sep 14 11:31:15 EDT 2017: ThreadId 25
Thu Sep 14 11:31:20 EDT 2017: ThreadId 26
Thu Sep 14 11:31:25 EDT 2017: ThreadId 28
Thu Sep 14 11:31:30 EDT 2017: ThreadId 30
The console output shows that the controller is called every 5 seconds . 控制台输出显示每5秒调用一次控制器。 But I'm sending the requests every 2 seconds .
但是我每2秒发送一次请求。
How could I handle multiple incoming requests concurrently? 如何同时处理多个传入请求? (I should see the console output every 2 seconds)
(我应该每2秒看到一次控制台输出)
UPDATE : 更新 :
If I send requests in different browsers, it works perfectly. 如果我在不同的浏览器中发送请求,则效果很好。 If I test it in the same browser/application which shares the session, the problem will come out.
如果我在共享会话的同一浏览器/应用程序中对其进行测试,则会出现问题。
Is it possible to accept concurrent multiple requests from same session ? 是否可以接受来自同一会话的并发多个请求?
Thanks! 谢谢!
By default Spring Boot web applications are multi-threaded and will handle multiple requests concurrently. 默认情况下,Spring Boot Web应用程序是多线程的,将同时处理多个请求。
This might be a browser specific quirk. 这可能是浏览器特定的问题。 On Windows 10, Chrome & Firefox do seem to queue multiple requests to the same URL, while IE, Edge, & curl do not.
在Windows 10上,Chrome和Firefox似乎确实将多个请求排队到同一URL,而IE,Edge和curl没有。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.