Parallel Method Input in Spring Controllers

In the simplest Spring (Boot) applications, I observe the following controller behavior, say

@CrossOrigin @RestController public class MyController { //... @RequestMapping(value = {"/lazy-dog"}) @ResponseBody public Rest lazyDog() { //... Thread.sleep(10000); // return Message("Dog exiting") } @RequestMapping(value = {"/quick-fox"}) @ResponseBody public Rest quickFox() { //... return Message("Fox exiting") } } 

namely, simultaneous writing to lazyDog() not allowed (calling twice from two browser tabs lasts 20sec ), while simultaneous execution of lazyDog() and quickFox() allowed (as the dog waits, the fox can quickly execute, say , in a separate browser tab).

What needs to be done to simultaneously make two or more lazyDog() calls?

Note. I am currently running the application through:

 @SpringBootApplication public class Application extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(Application.class); } public static void main(String[] args) { SpringApplication.run(Application.class, args); } } 
+5
source share
1 answer

I believe that you should test by opening two tabs in one browser (or in one browser). Can you try to access the URL at the same time in different two browsers (e.g. Chrome and IE or Chrome and Firefox, etc.).

I suspect that most likely it could be a specific browser implementation of simultaneous HTTP requests sent to the same host / URL.

+4
source

Source: https://habr.com/ru/post/1242637/


All Articles