文档上只有得到 当前运行的线程数量
我要获得正在运行的,我放进去的runable的实例 怎么得到
迷茫2017-04-17 11:34:44
There should be no such support at the API level. One possible way is to override the beforeExecute and afterExecute methods of ThreadPoolExecutor. You can write the log file before/after the task is executed, and your monitoring process/thread can poll the log to get the current Running task.
Or you can use some thread/inter-process communication methods (such as socket?) to get more real-time results.
巴扎黑2017-04-17 11:34:44
It is true that beforeExecute and afterExecute can be overridden, and then a shared ConcurrentHashMap can be opened. BeforeExecute puts Runnable into HashMap, and afterExecute deletes Runnable from HashMap.