Esempio
protected void finalize() throws Throwable {
Statement statement = getStatement();
try {
statement.clearBatch();
}
catch (SQLException exc) {
LogUtility.log(exc);
}
finally {
if (statement != null) {
try {
statement.close();
}
catch (SQLException exc) {
LogUtility.log(exc);
}
}
super .finalize();
}
}

private Statement getStatement() {
return _statement;
}

private transient Statement _statement;
Soluzione
Utilizzare un metodo di pulizia che venga esplicitamente richiamato invece del metodo finalize().
public void free() {
Statement statement = getStatement();
try {
statement.clearBatch();
}
catch (SQLException exc) {
LogUtility.log(exc);
}
finally {
if (statement != null) {
try {
statement.close();
}
catch (SQLException exc) {
LogUtility.log(exc);
}
}
}
}

private Statement getStatement() {
return _statement;
}

private transient Statement _statement;