necessary synchronization?

it is necessary to synchronize the being followed block of code or all the useless one?

privatefinallong inc(long value){

synchronized (this){

value++;

if (value == Long.MAX_VALUE){

value = 0;

}

}

return value;

}

Thank's

[713 byte] By [wcollazzoa] at [2007-10-3 11:31:27]
# 1
No. 'value' is a parameter to the method so it is only accessible by the current thread. The method has nothing to do with the data members of 'this' so it doesn't need to be synchronized. It could be static too.
ejpa at 2007-7-15 13:58:06 > top of Java-index,Core,Core APIs...
# 2
The code is threadsafe even without the syncronized block.
rb4ia at 2007-7-15 13:58:06 > top of Java-index,Core,Core APIs...
# 3
ejp answered this six days ago.
davidholmesa at 2007-7-15 13:58:06 > top of Java-index,Core,Core APIs...