ITeye博客

Java单例生成序列号

juncao2011 · 2010-11-16 09:33 · 编程语言 · Markdown

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

    }

}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。