com.qiniu.util.UniOrderUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of qsuits Show documentation
Show all versions of qsuits Show documentation
qiniu-suits is a efficient tools for qiniu api implemented by java8.
package com.qiniu.util;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicInteger;
public class UniOrderUtils {
private static ConcurrentMap orderMap = new ConcurrentHashMap<>();
private static AtomicInteger order = new AtomicInteger(0);
public static int getOrder() {
Integer ord = order.addAndGet(1);
Integer rem = ord % 5000;
if (ord > 5000 && rem == 0) rem = 5000;
while (ord > 5000) {
if (orderMap.remove(rem) != null) ord = rem;
}
return ord;
}
public static void returnOrder(int order) {
orderMap.put(order, order);
}
}