public MetricsForkJoinPoolMonitor(String name, ForkJoinPool fjPool) {
super(name, fjPool);
Metrics.register(metric(name, "status"), new Gauge<Status>() {
@Override
public Status getValue() {
final ForkJoinPool fjPool = fjPool();
if (fjPool.isTerminated()) // Returns true if all tasks have completed following shut down.
return ForkJoinPoolMonitor.Status.TERMINATED;
if (fjPool.isTerminating()) // Returns true if the process of termination has commenced but not yet completed.
return ForkJoinPoolMonitor.Status.TERMINATING;
if (fjPool.isShutdown()) // Returns true if this pool has been shut down.
return ForkJoinPoolMonitor.Status.SHUTDOWN;
if (fjPool.isQuiescent()) // Returns true if all worker threads are currently idle.
return ForkJoinPoolMonitor.Status.QUIESCENT;
return ForkJoinPoolMonitor.Status.ACTIVE;
}
});