Is there an easy way to tell you what tasks the Java executor is currently performing?

I’m sure that I could hack something that would allow me to figure it out, but I hope that there will be a ready-made solution that I’m just missing. I read the documents, but did not see anything.

In my particular application, it is used ThreadPoolExecutor, supported DelayQueue, although I'm not sure if this is important.

Thank!

+3
source share
3 answers

, . , (getTaskCount()/getCompletedTaskCount()). , AFAIK , , beforeExecute() afterExecute() .

+6

: , , , :

interface StartTaskWatcher {
    void taskStarted(Object data);
}

class StartTaskSignalingWrapper implements Runnable {
    private final Runnable task;
    private final String taskDescription;
    private final StartTaskWatcher startTaskWatcher;

    StartTaskSignalingWrapper(Runnable task, String taskDescription, StartTaskWatcher startTaskWatcher) {
        this.task = task;
        this.taskDescription = taskDescription;
        this.startTaskWatcher = startTaskWatcher;
    }

    public void run() {
        startTaskWatcher.taskStarted(taskDescription);
        task.run();
    }
}
+10

?

, , JVisualVM ( "bin" JDK). , .

(JVisualVM can also perform CPU / memory profiling using run-time and allocation hotspots and shows real-time garbage collection activity.)

+1
source

Source: https://habr.com/ru/post/1783735/


All Articles