Create VitroBackroundThread.getLivingThreads() method.

This commit is contained in:
j2blake 2011-11-17 21:17:25 +00:00
parent cbc53bd701
commit e6a34bf0a7

View file

@ -23,6 +23,9 @@ public class VitroBackgroundThread extends Thread {
private static final ConcurrentLinkedQueue<WeakReference<VitroBackgroundThread>> allThreads = new ConcurrentLinkedQueue<WeakReference<VitroBackgroundThread>>(); private static final ConcurrentLinkedQueue<WeakReference<VitroBackgroundThread>> allThreads = new ConcurrentLinkedQueue<WeakReference<VitroBackgroundThread>>();
/**
* Get a list of all VitroBackgroundThreads that have not been garbage-collected.
*/
public static List<VitroBackgroundThread> getThreads() { public static List<VitroBackgroundThread> getThreads() {
List<VitroBackgroundThread> list = new ArrayList<VitroBackgroundThread>(); List<VitroBackgroundThread> list = new ArrayList<VitroBackgroundThread>();
for (WeakReference<VitroBackgroundThread> ref : allThreads) { for (WeakReference<VitroBackgroundThread> ref : allThreads) {
@ -34,6 +37,19 @@ public class VitroBackgroundThread extends Thread {
return list; return list;
} }
/**
* Get a list of all VitroBackgroundThreads that have not died.
*/
public static List<VitroBackgroundThread> getLivingThreads() {
List<VitroBackgroundThread> list = new ArrayList<VitroBackgroundThread>();
for (VitroBackgroundThread t : getThreads()) {
if (t.isAlive()) {
list.add(t);
}
}
return list;
}
public enum WorkLevel { public enum WorkLevel {
IDLE, WORKING IDLE, WORKING
} }