当前位置:编程学习 > JAVA >>

Java单例生成序列号

 public class seqence6bit {
    private int seq = 100000;
    private seqence6bit() {

    }
    private static class seqence6bitcontainer {
        private static  seqence6bit instance = new seqence6bit();
    }

    public static seqence6bit getinstance() {
        
        return seqence6bitcontainer.instance;
    }

    public synchronized string getseq() {
      
            this.seq++;
            if (this.seq >= 1000000) {
                this.seq = 100000;
                return "100000";
            }

            return string.valueof(seq);

        }

}

补充:软件开发 , Java ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,