java - More than one user in the same Controller Spring MVC -


i'm starting develop web , i'm using spring mvc server framework. i'm wondering creating variables in controller class. had manage data in server, i'm concerned following case: if have more 1 user sending information same page, @ same time, 1 user interfere on user variable?

here's code example:

@controller public class mycontroller {      int number;       @requestmapping("/userinformation")     public string getinformation(int info) {        number = info;     }      public void dosomethingwithit() {        number = number + 1;    }  } 

in case, if have more 1 user sending data /userinformation @ same time, spring mvc create 1 controller each user? way wouldn't have problem, guess. if not, have rethink implementation, don't i?

the spring container create 1 instance of controller. users share instance.

if have data private user, have several options:

  1. store in http session (not recommended if it's lot of data, memory usage might explode)
  2. store in database , retrieve upon each request, based on property identifying user
  3. store in memory cache , retrieve upon each request, based on property identifying user

option 3 simple 1 of them, can implement map<user, userdata> instance variable on controller if like. it's not cleanest, beautiful or secure option, simple.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -