Hi,
I think we should not have instance variables in
servlets because multipl
thread share the instance variables and it will affect the data consistency
am i correct.
consider the example below
public class a extends HttpServlet{
protected LinkedList l=new LinkedList();
public void init(ServletConfig config){
for(int i=0;i<10;i++)
l.add(i);
}
public void doget() throws ServletExcetion,IOException{}
}
in this case the protected variable l were we are making add operation in init() will these not affect when multiple thread are executing together
say thread-1 will create the object and will be doing add operation.
in this time if thread-2 instantiates variable l will it not affetc the state of thread-1.
according to me it should affect both the threads but i am not able to find any difference when i execute the servlet it runs with out any problem.
let me know if i am missing some thing.
Thanks