---
title: "Java单例生成序列号"
author: "juncao2011"
date: "2010-11-16T09:33:15Z"
tags: []
categories: ["编程语言"]
slug: "java"
draft: false
lastmod: "2010-11-16T09:33:15Z"
id: 812397
url: "https://juncao2011.iteye.com/blog/812397"
---

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