Multithreaded execution where order of finished Work Items is preserved

后端 未结 9 1378
无人共我
无人共我 2021-02-01 08:28

I have a flow of units of work, lets call them \"Work Items\" that are processed sequentially (for now). I\'d like to speed up processing by doing the work multithreaded.

<
9条回答
  •  误落风尘
    2021-02-01 08:57

    I think that you need an extra queue to hold the incoming order. IncomingOrderQueue.

    When you consume the objects you put them in some storage, for example Map and then from another thread which consumes from the IncomingOrderQueue you pick the ids(hashes) of the objects and then you collect them from this HashMap.

    This solution can easily be implemented without execution service.

提交回复
热议问题