PDA

View Full Version : Connection leak



yugikhoi
24 Nov 2010, 7:08 PM
Hi everyone,

I try to use combobox load Arraystore with JSP backend. Everything works fine but I got connection leak happen whereas I closed all my connection after use. Below is my code:

Combobox+ Arraystore


var clientStore = new Ext.data.Store({
proxy: new Ext.data.HttpProxy(
new Ext.data.Connection({
url:'clientListSTR.jsp'
})
),
reader: new Ext.data.ArrayReader({}, [
{
name: 'caseID'
},{
name:'filenoteID'
},{
name: 'clientDisplay'
}
]),
remoteSort:false
});

var caseName_main = new Ext.form.ComboBox({
width: 250,
store: clientStore ,
valueField: 'caseID',
hiddenName: 'cmbcaseDetailsID',
displayField:'clientDisplay',
emptyText: 'Select Client',
editable: false,
typeAhead: true,
forceSelection: true,
mode: 'remote',
triggerAction: 'all',
selectOnFocus: true,
applyTo: 'clientcmb'
});


JSP code


Connection conn = null;
ResultSet rsClient = null;
PreparedStatement pstClient = null;

try {
conn = con();
String sqlClientSelect = "select statement........";

conn = con();
pstClient = conn.prepareStatement(sqlClientSelect);
rsClient = pstClient.executeQuery();

response.getWriter().write("[");
while (rsClient.next()) {
String caseNoID = rsClient.getString("caseNoID");
String clientID = rsClient.getString("ID");
String clientClaimNo = rsClient.getString("claimNumber");
String optClientFirstName = rsClient.getString("clientFirstName");
String optClientSurName = rsClient.getString("clientSurname");

response.getWriter().write("['" + caseNoID + "/" + clientID + "',"
+ "'" + clientClaimNo + "/" + optClientFirstName + " " + optClientSurName + "',"
+ "'" + optClientFirstName + " " + optClientSurName + " | " + clientClaimNo + "'],");
}
conn.close();
response.getWriter().write("['','','']");
response.getWriter().write("]");
response.getWriter().close();
} finally {
try {
if (conn != null) {
conn.close();
conn = null;
}
} catch (Exception ex) {
}
}


Thanks all.

Condor
25 Nov 2010, 7:21 AM
1. Why are you building JSON yourself? There are excellent libraries for that (e.g. json-lib or json-taglib).
2. Ever thought about connection pooling (using a DataSource)?

yugikhoi
25 Nov 2010, 4:01 PM
Hi Condor,

1. I build JSON myself because I don't want to embed any other lib in our project.
2. I am now using connection pool with JNDI in Glassfish Enterprise server. I also config server to detect and destroy connection leak by Leak claim so everytime leak connection happens, it is destroy in 10seconds. However, I just do not understant why it happens and I try to prevent it occur again. Works is not enough, optimize is our goal.

NOTES: I use the same method and jsp arraystore with Grid, groupingGrid but no connection leak happens, only combobox.
Thanks,

yugikhoi
25 Nov 2010, 9:49 PM
I got the solution, thanks all.