Tuesday 15 September 2015

How does Spring MVC handle multiple users -


I'm using spring for more than 6 months I was not able to understand the underlying mechanism related to the situation below I am

I have a spring web app I now autowired the model in the controller. The related method calls based on the matching url. All my methods are singleton

Now when two users are opening the spring app at the same time, they can run them parallel and give them results. I could not figure out how to do this. I mean that bean is singleton, i.e. the bean is not used or waiting to overwrite the data in the bean. But spring is working correctly.

My questions are clearly a piece of code to clarify below:

My default controller is a simple one:

  @ etovo-private App MODEL AMODEL; Public AppModel getModel () {back to aModel; } Public Zero Set MODEL (AP MODEL A Model) {this.aModel = aModel; } @RequestMapping (method = RequestMethod.GET) public modeland see defaultGueter (HttpServletRequest request, HttpServletResponse response) throws exception {ModelAndView mav = New ModelAndView (getViewName ()); Mav.addObject ("Model", aModel); Runtime.getRuntime () GC () .; Return mawa; }   

In addition to this, some people can tell me when two customers open the app, then when two different models are generated I use sailing. If only one model bean is all If the customer is present, then a request has been received from Customer 1 and I take 30 seconds to get the result. Now if the second client sends the request in 3 seconds, will the client request be overwritten first?

I think that is confusing me

how to get every web request Could? Generate a new thread.

Spring manages different scope (prototype, request, session, singleton). If singleton bean is used with two simultaneous requests, then bean stateless (or should be synchronized to avoid at least problems) If you use bean in the scope request, then a new instant for each request Will be generated. Spring manages this for you, but you have to be careful and use the right scope for your beans. Generally, your controller is a singleton but AppModel should be of the field request , otherwise you will have problems with two simultaneous requests.

"How is this magic happening?" About your last question, the answer is "aspect / proxy". Spring making Proxy Classes You can imagine that Spring will create a proxy in your AppModel class as soon as you try to access it in the controller, spring next correct example Call method for

No comments:

Post a Comment