484822 Jetty ThreadMonitor memory leak

This commit is contained in:
Jan Bartel 2015-12-23 14:12:47 +11:00
parent 8f4cc73613
commit 2dc78a5cd9
1 changed files with 18 additions and 0 deletions

View File

@ -24,8 +24,11 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.jetty.monitor.thread.ThreadMonitorException;
import org.eclipse.jetty.monitor.thread.ThreadMonitorInfo;
@ -321,6 +324,8 @@ public class ThreadMonitor extends AbstractLifeCycle implements Runnable
_runner.join();
}
catch (InterruptedException ex) {}
_monitorInfo.clear();
}
}
@ -424,6 +429,8 @@ public class ThreadMonitor extends AbstractLifeCycle implements Runnable
// retrieving a single thread stack trace.
Map<Thread,StackTraceElement[]> all = Thread.getAllStackTraces();
Set<Long> newOrUpdatedIds = new HashSet<Long>();
for (Map.Entry<Thread,StackTraceElement[]> entry : all.entrySet())
{
Thread thread = entry.getKey();
@ -490,7 +497,18 @@ public class ThreadMonitor extends AbstractLifeCycle implements Runnable
}
}
}
newOrUpdatedIds.add(Long.valueOf(threadId));
}
//clean out threads that no longer exist
Iterator<Long> iter = _monitorInfo.keySet().iterator();
while (iter.hasNext())
{
Long id = iter.next();
if (!newOrUpdatedIds.contains(id))
iter.remove();
}
newOrUpdatedIds.clear();
}
catch (Exception ex)
{