• Post Reply Bookmark Topic Watch Topic
  • New Topic

synchronized

 
Jawad Kakar
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are the draw backs of calling one synchronized method within another synchronized method if any?
Jawad
 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, it depends on what you synchronize:
If you sync on the same object then the executing thread will enter the second method and holding the very lock it already has -- there are no real drawbacks. Any other threads are excluded until the first thread leaves the first method.
If you sync on different objects then there are two drawbacks. One is related with the synchronization overhead and the other, and more important, is that you must be careful you should not run into a deadlock situation.
 
Jawad Kakar
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Leslie,
Thank you for your answer, that is what I was thinking. I am syn on the same object.
Thank you
Jawad Kakar
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!