All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.deepsense.neptune.clientlibrary.utils.ThreadBrowser Maven / Gradle / Ivy

There is a newer version: 1.6.1
Show newest version
/**
 * 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