producer/consumer work queues

前端 未结 3 971
眼角桃花
眼角桃花 2020-12-08 03:46

I\'m wrestling with the best way to implement my processing pipeline.

My producers feed work to a BlockingQueue. On the consumer side, I poll the queue, wrap what I

3条回答
  •  自闭症患者
    2020-12-08 04:05

    "find an available existing worker thread if one exists, create one if necessary, kill them if they go idle."

    Managing all those worker states is as unnecessary as it is perilous. I would create one monitor thread that constantly runs in the background, who's only task is to fill up the queue and spawn consumers... why not make the worker threads daemons so they die as soon as they complete? If you attach them all to one ThreadGroup you can dynamically re-size the pool... for example:

      **for(int i=0; i

提交回复
热议问题