我使用此代碼從數據庫表中獲取數據。重新加載多次後,JSF頁面會凍結
public List<Dashboard> getDashboardList() throws SQLException {
if (ds == null) {
throw new SQLException("Can't get data source");
}
//get database connection
Connection con = ds.getConnection();
if (con == null) {
throw new SQLException("Can't get database connection");
}
PreparedStatement ps = con.prepareStatement(
"SELECT * from GLOBALSETTINGS");
//get customer data from database
ResultSet result = ps.executeQuery();
List<Dashboard> list = new ArrayList<Dashboard>();
while (result.next()) {
Dashboard cust = new Dashboard();
cust.setUser(result.getString("SessionTTL"));
cust.setPassword(result.getString("MAXACTIVEUSERS"));
//store all data into a List
list.add(cust);
}
return list;
}
此代碼是部署在glassfish服務器上的JSF頁面的一部分。問題是,當我多次(大約8次)重新加載JSF頁面時,網頁凍結。我懷疑線程池是填充的,並且沒有空間用於新的連接。我如何解決這個問題?當查詢完成或有其他方法時關閉連接?
最良好的祝願
您能告訴我們如何配置該數據源嗎?它首先彙集在一起嗎? – 2012-03-08 20:31:30
這段代碼是否真的是你的jsf頁面的一部分(所以你使用的是JSP)?或者它是支持bean的一部分?如果是後者,bean的範圍是什麼? – 2012-03-08 20:32:48
我做了幾個屏幕截圖的池配置:http://imageshack.us/g/827/screenshotbg.png/ – 2012-03-08 20:48:18