如何让一个类只生成一个实例 ? see ajoo(jet pig)'s post:http://www.csdn.net/expert/topic/816/816993.xml?temp=.3531916 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 final class C{ private ca=new C(); private C(){} static C getC(){return ca;}} class c{private static int count = 1void c(){ count = count +1; if count > 1 then {??????????}} 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; }.........这是一个连接池的一部分,你可以知道怎么得到一个实例 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;}} 怎样合并动的GIF? 关于JDBC编程 在线跪求————怎样处理字符串中的空格!! 做一个计算器,我用键盘事件时,'.'怎么获取进去阿?高分相送! 程序有问题 用applet的repaint()方法能完全消除闪烁???? showModalDialog 的用法 Question??????? 求几本书的电子版,一本50分 在java程序中如何启动另一个应用程序,即如何调用其他的exe文件? 如何提取出特定格式的字符串内容?? 关于jar的打包问题
{
private ca=new C();
private C(){}
static C getC(){return ca;}
}
private static int count = 1void c(){
count = count +1;
if count > 1 then {??????????}
}
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;
}
.........这是一个连接池的一部分,你可以知道怎么得到一个实例
class a{
private static a;void a(){
}
public a getA()
{
if(a==null)
{
a = new a();
return a;
}
else
return a;
}}