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