Example
protected void finalize() throws Throwable {
Transaction trans = DBUtility.getTransaction();
try {
trans.commit();
}
catch (RollbackException exc) {
LogUtility.log(exc);
}
catch (HeuristicMixedException exc) {
LogUtility.log(exc);
}
catch (SystemException exc) {
LogUtility.log(exc);
}
catch (HeuristicRollbackException exc) {
LogUtility.log(exc);
}
finally {
super .finalize();
}
}
Solution
Use a cleanup method that is explicitly invoked instead of the finalize() method.
public void free() {
Transaction trans = DBUtility.getTransaction();
try {
trans.commit();
}
catch (RollbackException exc) {
LogUtility.log(exc);
}
catch (HeuristicMixedException exc) {
LogUtility.log(exc);
}
catch (SystemException exc) {
LogUtility.log(exc);
}
catch (HeuristicRollbackException exc) {
LogUtility.log(exc);
}
}