Home > Blockchain >  How to use Jackson JsonParser to read json coming as input stream, from multiple threads, object by
How to use Jackson JsonParser to read json coming as input stream, from multiple threads, object by

Time:06-30

I have a single inputstream of data, sending json. I want to read the data, object by object from multiple threads. The conventional single JsonParser is giving unwanted errors, as the nextToken() function gets invoked multiple times by multiple threads and in this way, not even a single thread is able to get the data properly.

How to send data in multiple threads without skipping any entry?

CodePudding user response:

you can't meaningfully parallelize the reading of a stream since, by its very nature, it is sequential. instead, you can have a single thread consume the stream, convert each object into some internal model instance and push that object on to some shared BlockingQueue. then you can have multiple threads consuming from the BlockingQueue and processing the objects in parallel.

  • Related