Use MultiThreading to read a file faster

后端 未结 3 1269
忘了有多久
忘了有多久 2020-12-06 15:43

I want to read a file of 500 Mb with the help of 2 threads, so that reading the file will be much faster. Someone please give me some code for the task using core java conce

相关标签:
3条回答
  • 2020-12-06 16:26

    While you might not be able to speed up the read from disc by using multiple threads to read the file you can speed up the process by not doing processing in the same thread as the read. This will be dependant on the contents of the file.

    0 讨论(0)
  • 2020-12-06 16:30

    Multi-threading is not likely to make the code faster at all. This because reading a file is an I/O-bound process. You will be limited by the speed of the disk rather than your processor.

    0 讨论(0)
  • 2020-12-06 16:37

    Instead of trying to multi-thread the reading, you may benefit from multi-threading the processing of the data. This can make it look like using multiple threads to read can help, but in reality, using one thread to read and multiple threads to process is often better.

    This often takes longer and is CPU bound. Using multiple threads to read files usually helps when you have multiple files on different physical disks (a rare occasion)

    0 讨论(0)
提交回复
热议问题