For starters, leave the service method alone. It's extremely unlikely that overriding it is the right thing to do, and much more likely that it's the wrong thing.
Instead, synchronize individual code sections in the doGet and/or doPost methods, making sure to keep those sections as short as possible. You may also want to look into the numerous other concurrency features Java has (ThreadLocal, volatile, java.util.concurrent, ...) that can prevent bad stuff from happening without resorting to explicit synchronization.
I'm sorry, but that's really bad. Firstly, it overrides the service method, which is the wrong thing to do. Secondly, it synchronizes the entire method, thereby completely destroying concurrency.
swapnl patil
Ranch Hand
Joined: Aug 13, 2007
Posts: 80
posted
0
Yeah I know that. But I don't know why this person want to do this.
In real world we place critical code in synchronized block.
raja pulleboina
Greenhorn
Joined: Dec 10, 2009
Posts: 12
posted
0
what happens if I do write synchronized block in service method... does it throws any exception or error..please explain..thanks
swapnl patil
Ranch Hand
Joined: Aug 13, 2007
Posts: 80
posted
0
It will not throw any error or exception,but if you make service method synchronized or used synchronized block for all code in Service method then you mess up the things. Only One thread will access service method and other need to wait. Its like you are implementing single thread model. Instead of this use synchronized block for critical code.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35438
9
posted
0
raja pulleboina wrote:what happens if I do write synchronized block in service method... does it throws any exception or error..
Again, do NOT override the service method; override the doGet and/or doPost method method instead.