How to read files in multithreaded mode?

后端 未结 4 1614
深忆病人
深忆病人 2021-01-06 00:40

I currently have a program that reads file (very huge) in single threaded mode and creates search index but it takes too long to index in single threaded environment.

<
4条回答
  •  梦毁少年i
    2021-01-06 00:51

    Your bottleneck is most likely the indexing, not the file reading. assuming your indexing system supports multiple threads, you probably want a producer/consumer setup with one thread reading the file and pushing each line into a BlockingQueue (the producer), and multiple threads pulling lines from the BlockingQueue and pushing them into the index (the consumers).

提交回复
热议问题