我有一个带有静态方法的类,该方法修改一个静态变量,这个方法需要同步以实现线程安全吗?
public final class IdManager {
private static int noOfIdsInReserveCurrently = 100;
private static final AtomicInteger allotedUserIdsCount;
public static int getNewId(){
noOfIdsInReserveCurrently--;
....
return allotedUserIdsCount.incrementAndGet();
}
}
这个方法是否应该被同步?