Im facing problem of threads while calling different methods of different classes from Servelts. 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..... regds, Manish Malhotra
The problem you are getting is probably due to thread synchronization. The servlet container creates a new thread for each servlet request unless the sevlet uses SingleThreadModel.But SingleThreadModel is deprecated and causes performance degradation. servlet specification says"Multipe servlets executing request threads may hae active access to a single sesin object at the same time. The developer has the responsibility for synchronizing access to session resources as appropriate" Coming to your problem, put the code which you don't want to be accessed by multiple instances in a synchronized block.You may follow other approaches as well.
As a general rule, thread synchronisation problems in servlets will be reduced if you eliminate or minimise all shared data. Try to avoid member data in your servlet class, using stack-based local variables instead.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.