All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.qiniu.util.UniOrderUtils Maven / Gradle / Ivy

There is a newer version: 8.4.8
Show newest version
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);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy