2
我在我的应用程序中使用数据库池(DB Pool)。我的DAO代码是这样的:问题与数据库池
static {
try {
PropertyUtil propertyUtil = new PropertyUtil();
propertyUtil.getBundle(Constants.DB_PROPERTIES);
String dburl = propertyUtil.getProperty("dburl");
String dbuserName = propertyUtil.getProperty("dbuserName");
String dbpassword = propertyUtil.getProperty("dbpassword");
String dbclass = propertyUtil.getProperty("dbclass");
String dbpoolName = propertyUtil.getProperty("dbpoolName");
int dbminPool = Integer.parseInt(propertyUtil
.getProperty("dbminPool"));
int dbmaxPool = Integer.parseInt(propertyUtil
.getProperty("dbmaxPool"));
int dbmaxSize = Integer.parseInt(propertyUtil
.getProperty("dbmaxSize"));
Class.forName(dbclass).newInstance();
moPool = new ConnectionPool(dbpoolName, dbminPool, dbmaxPool,
dbmaxSize, dburl, dbuserName, dbpassword);
moLogWrapper.info("Connection pool size: -"+Integer.valueOf(moPool.getSize()));
} catch (ApplicationException aoAppEx) {
moLogWrapper
.error(aoAppEx.getMessage(), aoAppEx.fillInStackTrace());
new ApplicationException(aoAppEx.getMessage(),
aoAppEx.fillInStackTrace());
} catch (IllegalAccessException aoIllEx) {
moLogWrapper
.error(aoIllEx.getMessage(), aoIllEx.fillInStackTrace());
new ApplicationException(aoIllEx.getMessage(),
aoIllEx.fillInStackTrace());
} catch (ClassNotFoundException aoCnfEx) {
moLogWrapper
.error(aoCnfEx.getMessage(), aoCnfEx.fillInStackTrace());
new ApplicationException(aoCnfEx.getMessage(),
aoCnfEx.fillInStackTrace());
} catch (InstantiationException aoIEx) {
moLogWrapper.error(aoIEx.getMessage(), aoIEx.fillInStackTrace());
new ApplicationException(aoIEx.getMessage(),
aoIEx.fillInStackTrace());
}
}
和我的openConnection()方法是:
public void openConnection() throws ApplicationException {
moLogWrapper.info("inside openConnection method");
try {
loCon = moPool.getConnection();
// moLogWrapper.info(moPool.getSize());
} catch (SQLException aoSqlEx) {
moLogWrapper
.error(aoSqlEx.getMessage(), aoSqlEx.fillInStackTrace());
if (null != loCon) {
loCon = null;
}
throw new ApplicationException(1002, aoSqlEx);
} catch (Exception aoEx) {
moLogWrapper.error(aoEx.fillInStackTrace());
throw new ApplicationException(aoEx.getMessage(),
aoEx.fillInStackTrace());
}
moLogWrapper.info("exiting openConnection method");
}
的问题是,我得到空的.openConnection方法从连接池类。 有一个在我的日志打印以及调试日志,打印以下行:
[snaq.db.ConnectionPool.sp] sp: Checkout - 10/10 (HitRate=40.186916%) - null returned
我无法理解返回空的原因是,我怎么能调试的实际问题。
编辑:
我的应用程序运行正常,但抛出的某个时候开始突然抛出此错误。
我使用postgres作为我的数据库。
请问您可以发布完整的错误stacktrace? –
启动时是否有错误? – Santosh
@Santosh:请参阅我的编辑部分的问题。该应用程序通常运行良好,但突然抛出此错误。 – Ankit