안녕하세요 Java 독립 실행 형 프로그램에 대한 연결 풀링을 만들었습니다.c3p0으로 연결 풀링을 처리하는 방법
그 particualr 데이터베이스 풀을 호출하는 모든 연결 .. 나는이 방법을 자주가는 두 differnt 한 데이터베이스 간의 getConnection(dbName)
Swithcing에게 전화를 할 때마다 내 DAO 클래스에서
private static ComboPooledDataSource = pooledDataSource;
public static void createDataSource(String dbName)
{
if(dbName.equals("DB_ONE"))
{
pooledDataSource = new ComboPooledDataSource();
// Here passing parameters will be different for DB_ONE
pooledDataSource.setDriverClass(dbDriver);
pooledDataSource.setJdbcUrl(dbUrl);
pooledDataSource.setUser(userID);
pooledDataSource.setPassword(password);
pooledDataSource.setMinPoolSize(Integer.parseInt(minCon));
pooledDataSource.setMaxPoolSize(Integer.parseInt(maxCon));
pooledDataSource.setMaxIdleTime(Integer.parseInt(maxIdleTime));
pooledDataSource.setInitialPoolSize(Integer.parseInt(intialPoolSize));
pooledDataSource.setPreferredTestQuery(testQuery);
}
if(dbName.equals("DB_TWO"))
{
pooledDataSource = new ComboPooledDataSource();
// Here passing parameters will be different for DB_TWO
pooledDataSource.setDriverClass(dbDriver);
pooledDataSource.setJdbcUrl(dbUrl);
pooledDataSource.setUser(userID);
pooledDataSource.setPassword(password);
pooledDataSource.setMinPoolSize(Integer.parseInt(minCon));
pooledDataSource.setMaxPoolSize(Integer.parseInt(maxCon));
pooledDataSource.setMaxIdleTime(Integer.parseInt(maxIdleTime));
pooledDataSource.setInitialPoolSize(Integer.parseInt(intialPoolSize));
pooledDataSource.setPreferredTestQuery(testQuery);
}
}
public Connection getConnection(String dbName)
{
createDataSource(dbName);
return pooledDataSource.getConnection();
}
.. 더 명확하게 할 좋아지고있다 다시 만들었습니다.
I 중복 풀을 만들려면 그나마...
어떻게 새로운 connection pool
생성 방지하기
도움이 고마워요. 방법 내부
왜 'getConnection()'을 호출 할 때마다 새 풀이 생성된다고 했습니까? 'ComboPooledDataSource'객체가 정적이지 않습니까? –
코드는 클래스로드시 한 번만 pooledDataSource를 만듭니다. 다른 클래스에도 정적 이니셜 라이저가 있습니까? – PeterMmm
새 풀이 생성되었음을 어떻게 알 수 있습니까? – Antoniossss