¿¹Á¦
protected void finalize() throws Throwable {
Connection connection = null;
try {
Driver driver = DBUtility.getDriver();
connection = driver.connect(DBUtility.getDBURL(), DBUtility.getUserProperties());
// ...
connection.commit();
}
catch (SQLException exc) {
LogUtility.log(exc);
}
finally {
if (connection != null) {
try {
connection.close();
}
catch (SQLException exc) {
LogUtility.log(exc);
}
}
super .finalize();
}
}
¼Ö·ç¼Ç
finalize() ¸Þ¼Òµå ´ë½Å ¸í½ÃÀûÀ¸·Î È£ÃâµÈ Á¤¸® ¸Þ¼Òµå¸¦ »ç¿ëÇϽʽÿÀ.
public void free() {
Connection connection = null;
try {
Driver driver = DBUtility.getDriver();
connection = driver.connect(DBUtility.getDBURL(), DBUtility.getUserProperties());
// finish some work
connection.commit();
}
catch (SQLException exc) {
LogUtility.log(exc);
}
finally {
if (connection != null) {
try {
connection.close();
}
catch (SQLException exc) {
LogUtility.log(exc);
}
}
}
}