【发布时间】:2016-03-03 04:52:19
【问题描述】:
这可能与Weird Error: CLOSE BY CLIENT STACK TRACE 重复但我提出了一个新问题,因为我没有看到 Log 的 isLoggable 方法。我将 org.apache.log4j.Logger 的 Logger 类用于我的日志目的。
我的错误是一样的
java.lang.Exception: DEBUG -- CLOSE BY CLIENT STACK TRACE
at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:566)
at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:234)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.destroyResource(C3P0PooledConnectionPool.java:470)
at com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask.run(BasicResourcePool.java:964)
我的代码是
public JSONObject getUserDetails(int id) {
System.setProperty("net.sf.ehcache.skipUpdateCheck", "true");
long lStartTime = new Date().getTime();
JSONObject obj = new JSONObject();
try (Session session = factory.openSession()) {
Employee emp = (Employee) session.load(Employee.class, id);
if (emp != null) {
obj.put("id", emp.getId());
obj.put("name", emp.getName());
}
long lEndTime = new Date().getTime();
log.info("[ Personal Details ]Time elapsed For Fetching :"
+ (lEndTime - lStartTime));
} catch (Exception e) {
log.error(e);
}
return obj;
}
编辑:
我的实现是:
public class PersonalisationImpl implements PersonalisationDao {
private void close( Throwable cause ) throws SQLException
{
close( cause, false );
}
private void close(Throwable cause, boolean b) {
// TODO Auto-generated method stub
assert Thread.holdsLock( this );
if ( logger.isLoggable( MLevel.FINEST ) )
logger.log( MLevel.FINEST, this + " closed by a client.",
new Exception("DEBUG -- CLOSE BY CLIENT STACK TRACE") );
}
isLoggable方法的方法应该在代码的哪里写,应该使用哪个logger类?
【问题讨论】:
标签: java hibernate logging c3p0