• Post Reply Bookmark Topic Watch Topic
  • New Topic

web services and use of synchronized methods  RSS feed

 
kiran kumar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a xfire webservice that was having concurrency issues (more than 1 request being called at the same time)... this was for a long running method call (between 15-20 seconds)... even 2 simultaneous requests was causing one or more requests to fail

the issue ranged from the business object returning incorrect ids (when creating new objects) to getting NullPointerExceptions and even Hibernate exceptions

i have fixed the issue by declaring the long running method as synchronized and this seems to work well. i have tested it with 16 simultaneous requests now (in production the system will typically NEVER deal with more than 5) and its working correctly...

my question is that is this the typical approach to resolve concurreny issues? and by default should i be declaring all methods that pose concurrency issues as synchronized
[ November 08, 2007: Message edited by: kiran kumar managal ]
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my question is that is this the typical approach to resolve concurreny issues?


That depends on the design of the "business object" - if your design only allows one to exist at a time and it is not designed for multithreaded access then you will have to synchronize to prevent processing more than one request "at one time."

Bill
 
kiran kumar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by William Brogden:


That depends on the design of the "business object" - if your design only allows one to exist at a time and it is not designed for multithreaded access then you will have to synchronize to prevent processing more than one request "at one time."

Bill


Bill thanks for the prompt reply. The business object in this case is a "product" (as in a product at an e-store)... The webservice allows adding a new product. I am using spring + hibernate + jpa + xfire here...

The concurrency issue happens when i try to save a new product that doesn't have an id already (cause its not persisted)

I cant think of anything in my design that doesnt lend itself to multithreaded access... but in a case like i have described here would you agree that the method for adding a product must be synchronized?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!