Follow the tasks presented by ThreadPoolExecutor

I am performing several tasks in ThreadPoolExecutor. I initialize it as follows:

private VideoExportExecutor executor; private BlockingQueue<Runnable> jobQueue; public void initialiseVideoProcessor() { jobQueue = new LinkedBlockingQueue<Runnable>(); executor = new VideoExportExecutor(1, 1, Long.MAX_VALUE, TimeUnit.SECONDS, jobQueue); } 

I implemented my own implementation of runnable ( VideoExportThread ), which contains the getProgress() method to track the progress of submitted tasks. I present examples of this as follows:

 executor.submit(new VideoExportThread(gcmPath)); 

I get the opportunity to request an executor / blockingQueue for current / waiting threads. I tried using jobQueue.toArray() and overriding the executing method beforeExecute(Thread t, Runnable r) , but in both cases the returned runnable is of type FutureTask, which does not contain a lot of data. Is there a way to use it to retrieve the original instance of VideoExportThread , to determine which ones are running, and to request its progress?

thanks

+4
source share
1 answer

Why not just keep a list of your runnables?

 List<Runnable> runnables = new ArrayList<> (); VideoExportThread r = new VideoExportThread(gcmPath); runnables.add(r); executor.submit(r); 

Also note that executor.submit(r); returns Future - you can call its isDone() method to check if the task is all running.


Lateral comment: there may be a good reason for managing the job queue manually, but if not, you use one of the factory methods to make your life easier. For example: ExecutorService executor = Executors.newCachedThreadPool(); .

+4
source

All Articles