SOLR-14162 TestInjection can leak Timer objects (#1137)

This commit is contained in:
Mike 2020-01-24 14:04:22 -06:00 committed by GitHub
parent 24f7a28ac1
commit eaa3dbe440
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -257,8 +257,9 @@ public class TestInjection {
if (rand.nextBoolean()) { if (rand.nextBoolean()) {
throw new TestShutdownFailError("Test exception for non graceful close"); throw new TestShutdownFailError("Test exception for non graceful close");
} else { } else {
final Timer timer = new Timer();
final Thread cthread = Thread.currentThread(); final Thread cthread = Thread.currentThread();
TimerTask task = new TimerTask() { TimerTask task = new TimerTask() {
@Override @Override
public void run() { public void run() {
@ -275,11 +276,10 @@ public class TestInjection {
} }
cthread.interrupt(); cthread.interrupt();
timers.remove(this); timers.remove(timer);
cancel();
} }
}; };
Timer timer = new Timer();
timers.add(timer); timers.add(timer);
timer.schedule(task, rand.nextInt(500)); timer.schedule(task, rand.nextInt(500));
} }