How can I handle rest calls parallely in spring boot ?
I created new spring boot 2.x application with one dependency
spring-boot-starter-web
Then I created basic controller like this
@RestController
@RequestMapping("/api/test")
public class HomeController {
private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
@GetMapping
public void longRunningMethod() throws InterruptedException {
logger.info("long running method start");
Thread.sleep(6000);
logger.info("long running method finished");
}
}
I run application (on localhost), open two web browsers and call it simultaneously.
I was expecting those calls will run in two separate threads paralelly hence finish roughly about the same time but here's console output.
2018-12-09 12:48:08.633 INFO 12192 --- [io-8080-exec-10] c.c.m.controller.HomeController : long running method start
2018-12-09 12:48:14.634 INFO 12192 --- [io-8080-exec-10] c.c.m.controller.HomeController : long running method finished
2018-12-09 12:48:14.683 INFO 12192 --- [io-8080-exec-10] c.c.m.controller.HomeController : long running method start
2018-12-09 12:48:20.683 INFO 12192 --- [io-8080-exec-10] c.c.m.controller.HomeController : long running method finished
As you can see calls were sequentially second call waits until first finish. What am I missing ?
Thanks