->when we synchronize the context or session attributes , the only one thread can access it...
so it means that we are indirectly making the single thread model,
some body told me to not use single thread model.somebody please explain
the disadvantage of single thread model also...
Synchronizing session, context objects means making any shared and modifiable data within them thread safe. That should be done very carefully to minimize the overhead. But the other methods (assuming synchronizing on a block inside the method) of the servlet instance is accessible to other threads. On the other hand the single thread model make the entire servlet instance dedicated to only one thread at a time. But even with that it's not possible to protect static members of the servlet instance or any other uses of context, session attributes without explicit synchronization. That's why it's deprecated as it doesn't give any good for the developer.
That statement shows how using incorrect language leads to errors.
If synchronization is necessary, you synchronize only on the access to attributes, as soon as the retrieval or modification is done, which should take very few CPU cycles, synchronization is dropped.
Javin Paul wrote:synchronization is very costly and affect the performance so make sure what you need to synchronize and as said minimize it as much as possible.
I don't think synchronization by itself is very costly in never versions of the JDK/JRE. However it does restrict what can process in parallel and so yes you do need to make sure synchronization is minimal as possible.