Subject | embedded server and bad code |
---|---|
Author | Niki Ivanchev |
Post date | 2004-05-28T14:04:11Z |
Recently I bumped into this problem
We had to convert java (swing) application that is build with firebird
server and Borlands dbSwing components to use embedded server
We decided to use connection pooling, since it is a huge program and I
hate borlands dbSwing components /there was a chance of several
connections needed somewhere/ . The problem we encounter is that
connections are never returned to pool, looks like either Borland or
developers relay on garbage collector to close Connections to database,
or the program is never used so much to reach 1024 limit. The program
is not client/server - the server and the client are installed into one
machine.
I workarounded this problem by simply refactoring the program and
creating a singleton, so now there is no chance for connection lost.
But I am wondering. If I open Connection using DriverManager in some
method and I do not explicitly close this connection, when method is
over and connection instance is not in scope, will GarbageCollector
close it or it will remain open.
example
void doSomething {
Connection c =
DriverManager.getConnection("jdbc:firebirdsql:embeded:c:\tem\bisisydemo.fdb?lc_ctype=UNICODE_FSS}","username","pass);
Statement st = c.PrepareStatement(///);
st.DoSomeFunnyThings.....
...
// no st.close or c.close
}
after doSomething finish - will connection remain open?
We had to convert java (swing) application that is build with firebird
server and Borlands dbSwing components to use embedded server
We decided to use connection pooling, since it is a huge program and I
hate borlands dbSwing components /there was a chance of several
connections needed somewhere/ . The problem we encounter is that
connections are never returned to pool, looks like either Borland or
developers relay on garbage collector to close Connections to database,
or the program is never used so much to reach 1024 limit. The program
is not client/server - the server and the client are installed into one
machine.
I workarounded this problem by simply refactoring the program and
creating a singleton, so now there is no chance for connection lost.
But I am wondering. If I open Connection using DriverManager in some
method and I do not explicitly close this connection, when method is
over and connection instance is not in scope, will GarbageCollector
close it or it will remain open.
example
void doSomething {
Connection c =
DriverManager.getConnection("jdbc:firebirdsql:embeded:c:\tem\bisisydemo.fdb?lc_ctype=UNICODE_FSS}","username","pass);
Statement st = c.PrepareStatement(///);
st.DoSomeFunnyThings.....
...
// no st.close or c.close
}
after doSomething finish - will connection remain open?