OddProblems
OddProblems

Reputation: 201

Inspect ExecutorService details

Is there a way to dig into an ExecutorServer object to see how many threads are currently being used?

Upvotes: 1

Views: 112

Answers (1)

Bozho
Bozho

Reputation: 597114

if (executor instanceof ThreadPoolExecutor) {
    int poolSize = ((ThreadPoolExecutor) executor).getPoolSize();
    // or
    int currentlyActive = ((ThreadPoolExecutor) executor).getActiveCount();
}

But generally, you should know that, because you have constructed the service (unless it is hidden in some bad API)

Upvotes: 2

Related Questions