io.deepsense.neptune.clientlibrary.utils.ThreadBrowser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of neptune-client-library Show documentation
Show all versions of neptune-client-library Show documentation
Enables integration with Neptune in your Java code
/**
* Copyright (c) 2016, CodiLime Inc.
*/
package io.deepsense.neptune.clientlibrary.utils;
import com.google.common.base.Preconditions;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public final class ThreadBrowser {
private final Collection threadsToIgnore;
public ThreadBrowser(Collection threadsToIgnore) {
this.threadsToIgnore = Preconditions.checkNotNull(threadsToIgnore);
}
public ThreadBrowser() {
this(Collections.emptyList());
}
public List getActiveThreads() {
Thread[] activeThreadBuffer = new Thread[Thread.activeCount()];
int threadCount = Thread.enumerate(activeThreadBuffer);
List allActiveThreads = Arrays.asList(activeThreadBuffer).subList(0, threadCount);
return allActiveThreads.stream()
.filter(thread -> !threadsToIgnore.contains(thread))
.collect(Collectors.toList());
}
public List getActiveThreadNames() {
return getActiveThreads().stream()
.map(Thread::getName)
.collect(Collectors.toList());
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy