Say servlet A doGet() is having getServletContext().setAttribute("x",94);
If synchronization is not implemented, servlet B can change the value of x.
Synchronizing doGet() does not solve the problem, because it ll stop other requests for the same servlet, but other servlets can still change the value of x.
If we synchronize on the getServletContext() object, say servlet A had set x value, came out of sync block, other servlet B will enter its sync block and change the value of x.
Next time servlet A comes in, and sees that the value has been changed.
Then what is the fun in synchronizing it?
When servlet A is accessing context object, all other servlets will be blocked to access the context since there is a lock on it.
Won't that hit the hundreds of servlets which have to wait to get the context object.
Using servlet context to store a user specific value would be very bad design, comparable to using instance variables.
The Servlet API very sensibly provides objects for holding values in various scopes, from request all the way to entire servers. You just need to find the right one. Wrapping your programmer mind-set around multiuser environment takes some work if you are only used to single user desktop applications.