Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concurrent method entry in Spring Controllers

In simplest Spring (Boot) applications I observe the following behavior of controllers, 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: concurrent entry into lazyDog() is not allowed (calling it twice from two browser tabs lasts 20sec), while concurrent execution of lazyDog() and quickFox() is allowed (as dog waits, fox can quickly execute, say in separate a browser tab).

What should be done to allow for concurrent execution of two or more calls to lazyDog()?

Note: I'm currently launching the app via:

@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);
    }
}
like image 386
P Marecki Avatar asked Sep 26 '22 10:09

P Marecki


1 Answers

I believe you must be testing by opening two tabs in a single browser (or single browser vendor). Can you try simultaneously accessing the URL in different two browsers vendors (say Chrome & IE or Chrome & Firefox etc).

I suspect it most probably could be browser specific implementation of simultaneous HTTP requests sending to same host/url.

like image 190
Madhusudana Reddy Sunnapu Avatar answered Sep 28 '22 04:09

Madhusudana Reddy Sunnapu