Java: ExecutorService that blocks on submission after a certain queue size

前端 未结 7 1411
Happy的楠姐
Happy的楠姐 2020-11-30 17:38

I am trying to code a solution in which a single thread produces I/O-intensive tasks that can be performed in parallel. Each task have significant in-memory data. So I want

7条回答
  •  Happy的楠姐
    2020-11-30 18:19

    I think it is as simple as using a ArrayBlockingQueue instead of a a LinkedBlockingQueue.

    Ignore me... that's totally wrong. ThreadPoolExecutor calls Queue#offer not put which would have the effect you require.

    You could extend ThreadPoolExecutor and provide an implementation of execute(Runnable) that calls put in place of offer.

    That doesn't seem like a completely satisfactory answer I'm afraid.

提交回复
热议问题