Search code examples
javaconcurrencyexecutorexecutors

Is there a simple way to tell what tasks a Java Executor is running at a given moment?


I'm sure I could hack something together which would enable me to figure this out, but I'm hoping there's an out-of-the-box solution I'm just missing. I read the docs but I didn't see anything.

My specific app is using a ThreadPoolExecutor backed by a DelayQueue, although I'm not sure that matters.

Thanks!


Solution

  • I don't think there is a reliable way to do this. If you want counts there are methods available (getTaskCount()/getCompletedTaskCount()) which help. If you need the actual tasks then AFAIK you need manually to keep track of the tasks, by overriding beforeExecute() and afterExecute() is one way.