My scenario is that there could be different users those could access the same servlets simoltaneously & from the service method Im callind different methods of the beans/simple classes which are interactig with database also.
If more then two users are accessing the same screen or other using the same servlet continuosly then its giving abrupt result. I know that every time the servlets called having the same instance but re exicuted the service methods. But I dnt know wat is happening.
And finnaly I made all the methods of my bean as sysnchronized & variables as volatile & finally made the call of the classes from servlet from the Synchronized block itself. But still get errors.
can any body plz help me. Its very urgent.Plz.....
Originally posted by Mark Spritzler:
And instance variables are not thread safe. The only thing thread safe in a Servlet are local variables. See my last night reading helped already.
If you are calling JavaBeans/other classes from your Servlet you need to make them threadsafe the same way as in any Java class would.
Thx to both of u 4 ur reply. But can u tell me that how to make the JavaBeans/other classes objects threadsafe as u r telling. Can I make all the variables locally defined in the method srevice & then made the service method synchronized.
Right now I hv done the service method & class methods synchronized & make bean variables as volatile.Its seems to be working fine.
But , I think it is not a good practice becz it will overloaded the servlet/classes.
Can anybody of u just give me more description.
Now to make the JavaBeans/other classes to be thread safe you need to use the Synchronized keyword on those methods in those classes.