java - Is Spring Boot MVC controller multithreaded? -


i'm new spring mvc , didn't find in doc. let's have controller /accounts accepts post requests create account. 2 requests comes (almost) in same time same account id. asfaik dispatcherservlet manages requests.

is 2nd request put in queue until first 1 has been completed? or there 2 threads working 2 requests simultaneously?

update: check official spring tutorial: building rest service. there controller method add:

@requestmapping(method = requestmethod.post) responseentity<?> add(@pathvariable string userid, @requestbody bookmark input) {     this.validateuser(userid);     return this.accountrepository             .findbyusername(userid)             .map(account -> {                 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<>(null, httpheaders, httpstatus.created);             }).get();  } 

controllers beans, default singleton. when 2 simultaneous requests received same instance of controller used 2 threads. let's imagine 1st thread saved new bookmark , executing

httpheaders.setlocation(servleturicomponentsbuilder                     .fromcurrentrequest().path("/{id}")                     .buildandexpand(result.getid()).touri()); 

meanwhile 2nd thread executed

bookmark result = bookmarkrepository.save(new bookmark(account,                     input.uri, input.description)); 

in case first thread return result.getid()).touri() created 2nd thread.

is correct workflow , controller thread-safe?

most servlets start separate thread each incoming request , spring isnt exception that. need make sure shared beans thread safe. otherwise spring takes care of rest.


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -