Hi, I am creating a servlet which creates and stores static data. Now the first time UserA calls this servlet and the data is created. My question is that what will happen when this servlet is called by UserB. 1. Will the same set of data will be shared by all. 2. Or a new set of data will be created for each different user.
very wild guess but....IMHO, it will be the same data, different data will not be created.. since static in java is a class property and not instance based.... am i even close ? i will be checking here..... - satya
Since the data set is static,the same dataset will be accessed.Think java servlet is also a java class. If the data is static,it belongs to the class alone not the instance of the class.. Thanx. Prabu.U
Joined: Nov 22, 2008
Madhav and Prabhu, thanks for your replies. Sanjana
And remember, unless you declare your servlet implements SingleThreadModel, there will only be one instance of the servlet which may have several Threads simultaneously executing it. This means that both instance and static variables are liable to modification every time the servlet is executed.