How to access the underlying queue of a ThreadpoolExecutor in a thread safe way

StackOverflow https://stackoverflow.com/questions/5935454

  •  30-10-2019
  •  | 
  •  

The getQueue() method provides access to the underlying blocking queue in the ThreadPoolExecutor, but this does not seem to be safe.

A traversal over the queue returned by this function might miss updates made to the queue by the ThreadPoolExecutor.

"Method getQueue() allows access to the work queue for purposes of monitoring and debugging. Use of this method for any other purpose is strongly discouraged."

What would you do if you wanted to traverse the workQueue used by the ThreadPoolExecutor? Or is there an alternate approach?

This is a continuation of.. Choosing a data structure for a variant of producer consumer problem

Now, I am trying the multiple producer multiple consumer, but I want to use some existing threadpool, since I don't want to manage the threadpool myself, and also I want a callback when ThreadPoolExecutor has finished executing some task alongwith the ability to examine in a thread safe way the "inprogress transactions" data structure.

没有正确的解决方案

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top