title: Is Spring Boot MVC controller multithreaded?
body: <p>I'm new to Spring MVC and I didn't find anything about this in doc.
  Let's say I have a controller /accounts which accepts POST requests to create an account.
  Two requests comes (almost) in the same time with the same account id.
  ASFAIK <code>dispatcherServlet</code> manages the requests.</p>
  
  <p>Is the 2nd request put in queue until the first one has been completed?
  Or there would be two threads working with two requests simultaneously? </p>
  
  <p><strong>UPDATE:</strong>
  Check the official Spring tutorial: <a href="http://spring.io/guides/tutorials/bookmarks/#_building_a_rest_service" rel="noreferrer">Building a REST service</a>.
  There is controller with method <code>add</code>:</p>
  
  <pre><code>@RequestMapping(method = RequestMethod.POST)
  ResponseEntity&lt;?&gt; add(@PathVariable String userId, @RequestBody Bookmark input) {
      this.validateUser(userId);
      return this.accountRepository
              .findByUsername(userId)
              .map(account -&gt; {
                  Bookmark result = bookmarkRepository.save(new Bookmark(account,
                          input.uri, input.description));
  
                  HttpHeaders httpHeaders = new HttpHeaders();
                  httpHeaders.setLocation(ServletUriComponentsBuilder
                          .fromCurrentRequest().path("/{id}")
                          .buildAndExpand(result.getId()).toUri());
                  return new ResponseEntity&lt;&gt;(null, httpHeaders, HttpStatus.CREATED);
              }).get();
  
  }
  </code></pre>
  
  <p>Controllers are just beans, by default they are singleton. 
  When two simultaneous requests are received the same instance of the controller is used by two threads. Let's imagine the 1st thread already saved new bookmark and executing </p>
  
  <pre><code>httpHeaders.setLocation(ServletUriComponentsBuilder
                      .fromCurrentRequest().path("/{id}")
                      .buildAndExpand(result.getId()).toUri());
  </code></pre>
  
  <p>Meanwhile the 2nd thread just executed </p>
  
  <pre><code>Bookmark result = bookmarkRepository.save(new Bookmark(account,
                      input.uri, input.description));
  </code></pre>
  
  <p>In this case the first thread will return <code>result.getId()).toUri()</code> which is created by the 2nd thread. </p>
  
  <p>Is it correct workflow and is this controller thread-safe?</p>