1

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

1

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi Andrei. Thank you for a prompt answer.
1

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

1 Comment

Hi Deadpool. Thank you for a prompt answer.
1

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

2 Comments

Hi NiksVij. Thank you for a prompt answer. My is deployed in WebLogic container so from the response, the WebLogic will create a new thread to process each request. Is there a way to confirm this is happening on WebLogic or some other way. ?
Hey Pete. I don't have much experience on WebLogic , but i think you should be able to confirm the above by taking help from this: stackoverflow.com/questions/1323408/… and adding few log statements . Hope it helps :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.