com.feingto.iot.common.util.id.IncrementIdGenerator Maven / Gradle / Ivy
package com.feingto.iot.common.util.id;
import java.util.concurrent.atomic.AtomicInteger;
/**
* 自增ID生成实现
*
* @author longfei
*/
public class IncrementIdGenerator implements IdGenerator {
private static AtomicInteger index = new AtomicInteger(1);
private static int messageId() {
for (; ; ) {
int current = index.get();
int next = (current >= Integer.MAX_VALUE ? 0 : current + 1);
if (index.compareAndSet(current, next)) {
return current;
}
}
}
@Override
public Integer nextId() {
return messageId();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy