`
juncao2011
  • 浏览: 9786 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

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);

        }

}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics