chris brat said:
I dont think that adding the synchronized keyword will cause you a
problem with either compilation or running - it didn't in the simple
example class I wrote.
But why would you want to do this? it would kill performance.
The functionality seems to describe the behaviour of the
SingleThreadModel which was deprecated.
SingleThreadModel is quite a different beast than synchronized service
method. Ok, both guarantee, that there is just one thread running
in the service method of a single servlet instance.
Then to the difference: if you use SingleThreadModel, the servlet container
will be allowed to create multiple instances of your servlet class
to allow concurrent processing of multiple requests (which would be
a big no-no, if you chose the SingleThreadModel to protect some fragile
constructs you access from within the service method). If, on the other
hand, you synchronize the service method (and do not use the
SingleThreadModel), the container will be limited to just one instance
of any given servlet - thus permitting just one request running in
the service method of the servlet. However, this would be a major
performance bottleneck; it'd be better to use some more fine-grained
locking.