File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Services and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark ""Synchronized" method in Web Services" Watch ""Synchronized" method in Web Services" New topic

"Synchronized" method in Web Services

Jayakrishnan R Nair

Joined: Jan 24, 2008
Posts: 5

HI All,

I have a crazy question.

If I mark my web service method as "synchronized", will app server put all the web service requests in serial.

Means only one execution of the method takes place at a given time.

For normal threads or java application , that is the behaviour.

Theory is when you know something, but it doesn't work.<br />Practice is when something works, but you don't know why.<br />Programmers combine theory and practice: Nothing works and they don't know why.
Vinod K Singh
Ranch Hand

Joined: Sep 30, 2008
Posts: 198
May be or many not. App server may create many instances of service implementation class to serve the class. All depends on how web service is exposed and using which framework. By default JAX-WS RI creates a singleton instance of the implementation class in that scenario everything may go in serial.

My Blog
Gabriel Vince

Joined: Feb 05, 2009
Posts: 24
you may still get into trouble later, when you put your application into more server nodes.. the application will not be serialized anyway.
IMHO maybe you should not serialize request on the level of WS (vinod is right, a server may use as many service instances as it wishes), but maybe on the backend (as a sigleton service class, database level, ..)..

I agree. Here's the link:
subject: "Synchronized" method in Web Services
jQuery in Action, 3rd edition