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

com.alibaba.rocketmq.client.common.ThreadLocalIndex Maven / Gradle / Ivy

There is a newer version: 3.6.2.Final
Show newest version
package com.alibaba.rocketmq.client.common;

import java.util.Random;

public class ThreadLocalIndex {
    private final ThreadLocal threadLocalIndex = new ThreadLocal();

    public ThreadLocalIndex(int value) {

    }

    public int getAndIncrement() {
        Integer index = this.threadLocalIndex.get();
        if (null == index) {
            index = new Integer(Math.abs(new Random().nextInt()));
            if (index < 0) index = 0;
            this.threadLocalIndex.set(index);
        }

        index = Math.abs(index + 1);
        if (index < 0)
            index = 0;

        this.threadLocalIndex.set(index);
        return index;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy