see ajoo(jet pig)'s post:
http://www.csdn.net/expert/topic/816/816993.xml?temp=.3531916

解决方案 »

  1.   

    final class C
    {
      private ca=new C();
      private C(){}
      static C getC(){return ca;}
    }
      

  2.   

    class c{
    private static int count = 1void c(){
      count = count +1;
      if count > 1 then {??????????}
    }
      

  3.   

    public class ConnectionPool {
      private static ConnectionPool instance;
      private int client = 0;;
      private String userName;
      private String driverName;
      private String passWord;
      private Vector freeConn = new Vector();
      private String dbURL;
      private int maxConn;  private ConnectionPool() {
        driverName = Log.getValue("DB_DRIVER_NAME");
        userName = Log.getValue("DB_USERNAME");
        passWord = Log.getValue("DB_PASSWORD");
        dbURL = Log.getValue("DB_URL");
        try{
          maxConn = Integer.parseInt(Log.getValue("DB_MAXCONN"));
        } catch(NumberFormatException nfec) {
          Log.log("ConnectionPool.ConnectionPool",nfec.toString());
          maxConn = 100; //默认最大连接数为100
        }
        loadDriver();
      }  public static synchronized ConnectionPool getInstance(){
        if(instance == null) {
          instance = new ConnectionPool();
        }
        return instance;
      }
    .........这是一个连接池的一部分,你可以知道怎么得到一个实例
      

  4.   

    singleton设计模式,可以依靠一个计数器或者静态变量来实现。bbshero和cxj-2000已作说明。
    class a{
    private static a;void a(){
             }
    public a getA()
    {
      if(a==null)
       {
          a = new a();
          return a;
       }
       else
         return a;
    }}