Concurrent processing of single InputStream with independent consumers

后端 未结 3 1937
迷失自我
迷失自我 2021-02-15 23:48

I need to spawn N consumer threads, which process same InputStream concurrently, e.g - transform it somehow, calculate checksum or digital signature etc. These consumers do not

3条回答
  •  独厮守ぢ
    2021-02-16 00:26

    Have you considered using pipe streams? Your producer can have a one or more PipedOuputStream in which it throws whatever it reads from the file. At the other side of the pipes, you have different consumer threads reading on a corresponding PipedInputstream (which is an InputStream that you can share with your libraries).

    Your producer thread can decide through which of the pipes data should be sent, by means of this, providing data to be processed for a given consumer thread reading on the other side of the pipe.

    If you need to get data back from your consumer threads, then you can create another pipe, in the opposite direction, to send the data back to you.

提交回复
热议问题