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

cn.teleinfo.idpointer.sdk.session.SessionIdFactoryDefault Maven / Gradle / Ivy

Go to download

基于Java语言开发的工业互联网标识解析体系客户端软件开发工具包,应用通过集成 id-pointer-sdk,快速对接标识解析、标识注册、标识维护等功能服务。

The newest version!
package cn.teleinfo.idpointer.sdk.session;

import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;

public class SessionIdFactoryDefault implements SessionIdFactory{

    private AtomicInteger atomicInteger = new AtomicInteger(10000);
    @Override
    public int getNextInteger() {
        int i = atomicInteger.incrementAndGet();
        if (i < 0) {
            synchronized (this) {
                i = atomicInteger.get();
                if (i < 0) {
                    atomicInteger.set(1);
                    i = 1;
                }
            }
        }
        return i;
    }

    private static SessionIdFactory sessionIdFactory;
    public static SessionIdFactory getInstance() {
        if (sessionIdFactory == null) {
            synchronized (SessionIdFactoryDefault.class) {
                if (sessionIdFactory == null) {
                    sessionIdFactory = new SessionIdFactoryDefault();
                }
            }
        }
        return sessionIdFactory;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy