Java: ArrayBlockingQueue vs. LinkedBlockingQueue

前端 未结 2 2057
情深已故
情深已故 2020-12-24 14:09

I think that, in most cases, the ArrayBlockingQueue will perform better than the LinkedBlockingQueue. However, that is the case when there is alway

2条回答
  •  攒了一身酷
    2020-12-24 15:11

    My 2 cents:

    To start with, the bottom line here is you don't really care about the difference here because even when you are using a plain LinkedBlockingQueue, the performance is good enough when you are delivering some micro-second level systems. So the performance difference here isn't really that great.

    If you are writing a mission-critical high performance system and you are using queues to pass messages between threads, you can always estimate the queue size needed by [Queue Size] = [Max acceptable delay] * [Max message rate]. Anything which can grow beyond such capacity means you suffer from a slow consumer problem. In a mission critical application, such delay means your system is malfunctioning. Some manual process might be needed to make sure the system is running properly.

    In case your system isn't mission critical, you can simply pause (block) the publisher until some consumers are available.

提交回复
热议问题