Remove redundant code from LeakTask

pull/192/head
Brett Wooldridge 11 years ago
parent 586c68b64d
commit 264e0bb3ca

@ -33,13 +33,11 @@ public class LeakTask implements Runnable
{ {
private static final Logger LOGGER = LoggerFactory.getLogger(LeakTask.class); private static final Logger LOGGER = LoggerFactory.getLogger(LeakTask.class);
private final long leakTime;
private final ScheduledFuture<?> scheduledFuture; private final ScheduledFuture<?> scheduledFuture;
private StackTraceElement[] stackTrace; private StackTraceElement[] stackTrace;
public LeakTask() public LeakTask()
{ {
leakTime = 0;
scheduledFuture = null; scheduledFuture = null;
} }
@ -47,7 +45,6 @@ public class LeakTask implements Runnable
{ {
this.stackTrace = new Exception().getStackTrace(); this.stackTrace = new Exception().getStackTrace();
this.leakTime = System.currentTimeMillis() + leakDetectionThreshold;
scheduledFuture = executorService.schedule(this, leakDetectionThreshold, TimeUnit.MILLISECONDS); scheduledFuture = executorService.schedule(this, leakDetectionThreshold, TimeUnit.MILLISECONDS);
} }
@ -55,14 +52,12 @@ public class LeakTask implements Runnable
@Override @Override
public void run() public void run()
{ {
if (System.currentTimeMillis() > leakTime) { StackTraceElement[] trace = new StackTraceElement[stackTrace.length - 3];
StackTraceElement[] trace = new StackTraceElement[stackTrace.length - 3]; System.arraycopy(stackTrace, 3, trace, 0, trace.length);
System.arraycopy(stackTrace, 3, trace, 0, trace.length);
LeakException e = new LeakException(trace); LeakException e = new LeakException(trace);
LOGGER.warn("Connection leak detection triggered, stack trace follows", e); LOGGER.warn("Connection leak detection triggered, stack trace follows", e);
stackTrace = null; stackTrace = null;
}
} }
public void cancel() public void cancel()

@ -33,13 +33,11 @@ public class LeakTask implements Runnable
{ {
private static final Logger LOGGER = LoggerFactory.getLogger(LeakTask.class); private static final Logger LOGGER = LoggerFactory.getLogger(LeakTask.class);
private final long leakTime;
private final ScheduledFuture<?> scheduledFuture; private final ScheduledFuture<?> scheduledFuture;
private StackTraceElement[] stackTrace; private StackTraceElement[] stackTrace;
public LeakTask() public LeakTask()
{ {
leakTime = 0;
scheduledFuture = null; scheduledFuture = null;
} }
@ -47,7 +45,6 @@ public class LeakTask implements Runnable
{ {
this.stackTrace = new Exception().getStackTrace(); this.stackTrace = new Exception().getStackTrace();
this.leakTime = System.currentTimeMillis() + leakDetectionThreshold;
scheduledFuture = executorService.schedule(this, leakDetectionThreshold, TimeUnit.MILLISECONDS); scheduledFuture = executorService.schedule(this, leakDetectionThreshold, TimeUnit.MILLISECONDS);
} }
@ -55,14 +52,12 @@ public class LeakTask implements Runnable
@Override @Override
public void run() public void run()
{ {
if (System.currentTimeMillis() > leakTime) { StackTraceElement[] trace = new StackTraceElement[stackTrace.length - 3];
StackTraceElement[] trace = new StackTraceElement[stackTrace.length - 3]; System.arraycopy(stackTrace, 3, trace, 0, trace.length);
System.arraycopy(stackTrace, 3, trace, 0, trace.length);
LeakException e = new LeakException(trace); LeakException e = new LeakException(trace);
LOGGER.warn("Connection leak detection triggered, stack trace follows", e); LOGGER.warn("Connection leak detection triggered, stack trace follows", e);
stackTrace = null; stackTrace = null;
}
} }
public void cancel() public void cancel()

@ -115,7 +115,7 @@ public class MiscTest
ps.close(); ps.close();
String s = new String(baos.toByteArray()); String s = new String(baos.toByteArray());
Assert.assertNotNull("Exception string was null", s); Assert.assertNotNull("Exception string was null", s);
Assert.assertTrue("Expected exception to contain 'Connection leak detection' but contains\n" + s, s.contains("Connection leak detection")); Assert.assertTrue("Expected exception to contain 'Connection leak detection' but contains *" + s + "*", s.contains("Connection leak detection"));
} }
finally finally
{ {

Loading…
Cancel
Save