Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

synchronization in static methods  RSS feed

 
Brian Nice
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When do you need to place synchronized in a method declaration?
If I have a class with a static method that can be called by other classes, does that method need to be synchronized? For example, does the following method need to be synchronized as the val being passed in could be overwritten by different callers?:
public int static getValuePlusFive(int val) {
int x = val + 5;
return x;
}
It does it only need to be synchronized if the method accesses say come class variables that get changed in the method?
Thanks for clearing my confusion
Brian
 
sridhar satuloori
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brian,
See the following post i think it gives answer to ur query
http://www.coderanch.com/t/231842/threads/java/Synchronizing-static-method
--Sridhar
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!