static ForkJoinPoolMonitor createForkJoinPoolMonitor(String name, ForkJoinPool fjPool, MonitorType monitorType) { if (monitorType == null) return null; switch (monitorType) { case JMX: return new JMXForkJoinPoolMonitor(name, fjPool); case METRICS: return new MetricsForkJoinPoolMonitor(name, fjPool); case NONE: return null; default: throw new RuntimeException("Unsupported monitor type: " + monitorType); } }
@Override public Integer getValue() { return fjPool().getQueuedSubmissionCount(); } });
@Override protected ForkJoinPool fjPool() { final ForkJoinPool fjPool = super.fjPool(); if (fjPool == null) { unregister(); throw new RuntimeException("Pool collected"); } return fjPool; } }
public MetricsForkJoinPoolMonitor(String name, ForkJoinPool fjPool) { super(name, fjPool); Metrics.register(metric(name, "status"), new Gauge<Status>() { @Override public Status getValue() { Metrics.register(metric(name, "asyncMode"), new Gauge<Boolean>() { @Override public Boolean getValue() { Metrics.register(metric(name, "parallelism"), new Gauge<Integer>() { @Override public Integer getValue() { Metrics.register(metric(name, "poolSize"), new Gauge<Integer>() { @Override public Integer getValue() { Metrics.register(metric(name, "activeThreadCount"), new Gauge<Integer>() { @Override public Integer getValue() { Metrics.register(metric(name, "runningThreadCount"), new Gauge<Integer>() { @Override public Integer getValue() { Metrics.register(metric(name, "queuedSubmissionCount"), new Gauge<Integer>() { @Override public Integer getValue() {
@Override public Integer getValue() { return fjPool().getParallelism(); // Returns the targeted parallelism level of this pool. } });
@Override public Long getValue() { return fjPool().getQueuedTaskCount(); } });
@Override public Integer getValue() { return fjPool().getPoolSize(); // Returns the number of worker threads that have started but not yet terminated. } });
@Override public Integer getValue() { return fjPool().getRunningThreadCount(); } });
@Override public Long getValue() { return fjPool().getStealCount(); } });
@Override public Boolean getValue() { return fjPool().getAsyncMode(); } });
@Override public Integer getValue() { return fjPool().getActiveThreadCount(); } });
@Override public Long[] getValue() { long[] res = new ExecutorServiceLatencyProbe(fjPool(), 5).fire(); Long[] ret = new Long[res.length]; for (int i = 0; i < res.length; i++) ret[i] = res[i]; return ret; } });
@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; } });