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