示例
protected
void
finalize()
throws
Throwable {
try
{
getContext().close();
}
catch
(
NamingException
exc) {
LogUtility.log(exc);
}
finally
{
super
.finalize();
}
}
private
Context
getContext() {
return
_context;
}
private
transient
Context
_context;
解决方案
使用显式调用的 cleanup 方法来代替 finalize() 方法。
public
void
free() {
try
{
getContext().close();
}
catch
(
NamingException
exc) {
LogUtility.log(exc);
}
}
private
Context
getContext() {
return
_context;
}
private
transient
Context
_context;