Példa
protected void finalize() throws Throwable {
Connection conn = null;
try {
conn = getConnection();
conn.close();
}
catch (SQLException exc) {
LogUtility.log(exc);
}
finally {
if (conn != null) {
try {
conn.close();
}
catch (SQLException exc) {
LogUtility.log(exc);
}
}
super .finalize();
}
}

private Connection getConnection() {
return _connection;
}

private transient Connection _connection = null;
Megoldás
A finalize() metódus helyett használjon egy kifejezetten meghívott takarító metódust.
public void free() {
Connection conn = null;
try {
conn = getConnection();
conn.close();
}
catch (SQLException exc) {
LogUtility.log(exc);
}
finally {
if (conn != null) {
try {
conn.close();
}
catch (SQLException exc) {
LogUtility.log(exc);
}
}
}
}

private Connection getConnection() {
return _connection;
}

private transient Connection _connection = null;