Minor improvements to LeakTask.

pull/192/head
Brett Wooldridge 10 years ago
parent c04f59f3b8
commit b959a79dc7

@ -42,7 +42,7 @@ public class LeakTask implements Runnable
public LeakTask(final long leakDetectionThreshold, final ScheduledExecutorService executorService)
{
this.stackTrace = Thread.currentThread().getStackTrace();
this.stackTrace = new Exception().getStackTrace();
this.leakTime = System.currentTimeMillis() + leakDetectionThreshold;
scheduledFuture = executorService.schedule(this, leakDetectionThreshold, TimeUnit.MILLISECONDS);
@ -56,8 +56,7 @@ public class LeakTask implements Runnable
StackTraceElement[] trace = new StackTraceElement[stackTrace.length - 3];
System.arraycopy(stackTrace, 4, trace, 0, trace.length);
Exception e = new Exception();
e.setStackTrace(trace);
LeakException e = new LeakException(trace);
LoggerFactory.getLogger(LeakTask.class).warn("Connection leak detection triggered, stack trace follows", e);
stackTrace = null;
}
@ -70,4 +69,17 @@ public class LeakTask implements Runnable
scheduledFuture.cancel(false);
}
}
private static class LeakException extends Exception
{
private static final long serialVersionUID = -2021997004669670337L;
/**
* No-op constructor to avoid the call to fillInStackTrace()
*/
public LeakException(final StackTraceElement[] stackTrace)
{
this.setStackTrace(stackTrace);
}
}
}

@ -42,7 +42,7 @@ public class LeakTask implements Runnable
public LeakTask(final long leakDetectionThreshold, final ScheduledExecutorService executorService)
{
this.stackTrace = Thread.currentThread().getStackTrace();
this.stackTrace = new Exception().getStackTrace();
this.leakTime = System.currentTimeMillis() + leakDetectionThreshold;
scheduledFuture = executorService.schedule(this, leakDetectionThreshold, TimeUnit.MILLISECONDS);
@ -56,8 +56,7 @@ public class LeakTask implements Runnable
StackTraceElement[] trace = new StackTraceElement[stackTrace.length - 3];
System.arraycopy(stackTrace, 4, trace, 0, trace.length);
Exception e = new Exception();
e.setStackTrace(trace);
LeakException e = new LeakException(trace);
LoggerFactory.getLogger(LeakTask.class).warn("Connection leak detection triggered, stack trace follows", e);
stackTrace = null;
}
@ -70,4 +69,17 @@ public class LeakTask implements Runnable
scheduledFuture.cancel(false);
}
}
private static class LeakException extends Exception
{
private static final long serialVersionUID = -2021997004669670337L;
/**
* No-op constructor to avoid the call to fillInStackTrace()
*/
public LeakException(final StackTraceElement[] stackTrace)
{
this.setStackTrace(stackTrace);
}
}
}

Loading…
Cancel
Save