Reputation: 107
Below is a snippet of an existing Rest Interface implementation.
@RestController
@RequestMapping("/login")
public class LoginController {
@Autowired
private LoginProcessor loginProcessor;
@RequestMapping(
consumes = MediaType.TEXT_XML_VALUE,
produces = { MediaType.TEXT_XML_VALUE,
MediaType.APPLICATION_JSON_VALUE },
value = "/v1/login",
method = RequestMethod.POST)
public LoginResponse loginRequest(
@RequestBody String credentials) throws JAXBException {
return loginProcessor.request(credentials);
}
}
If the REST call to loginRequest() is initiated from different clients, and possibly, at the same time :-
1) Will a new thread be created to handle each request. Therefore, all requests are being processed concurrently ?
or
2) Is there one thread to handle all requests, which would mean only loginRequest() is being executed at any one time, and other request are queued up ?
I would ideally like to the interface to be able to handle multiple requests at any one time.
Thank you for your help in both clarifying and furthering my understanding on the subject.
Pete
Upvotes: 1
Views: 82
Reputation: 193
I suppose you are using spring framework ( as you have used Autowired and other annotations). Thus to ans your ques: Yes spring will create new thread for each new request. Kindly refer to this answer, this should solve your queries
https://stackoverflow.com/a/17236345/7622687
Upvotes: 1
Reputation: 40078
Every application should run in server either web server (tomcat) or application server (web logic), by default tomcat web container will have 200 threads ( you can adjust as your wish), so 200 threads can process concurrently at a time in tomcat
For every input request will be taken by web container thread and next to dispatcher servlet to corresponding controller class
Upvotes: 1
Reputation: 245
You can search stack overflow for this type of question as it has been answered before. You can read these answers: https://stackoverflow.com/a/7457252/10632970 https://stackoverflow.com/a/17236345/10632970
Good luck with your studies.
Upvotes: 1