multithreading - How to write java thread pool programme to read content of file? -


I want to define a thread pool with 10 threads and read the contents of the file. But different threads should not read the same content (such as dividing the content into 10 pieces and reading each piece through each thread)

"post-text" itemprop = "text">

OK That's what you will do, it'll be almost:

  1. Get the length of the file,
  2. divide by N.
  3. N Go to each (file_size / n) * thread_no and enter (file_size / n) bytes in buffer Read
  4. Wait for all threads to complete.
  5. Stack buffers together.

(If you were a bit clever about it, then you can avoid the last step ...)

But, it is doubtful that you do so Will gain momentum. Actually, I would not be surprised if you are slow in many cases. With a typical OS, I hope you get better performance by reading a file using a good <,> one (<...> call from a thread) file.

If you read it sequentially, then you can get data quickly from the OS disc. Indeed, many OSes are optimized for this usage-case, and use reading-forward and in-memory buffering (OS-level buffers) to give high effective reading rate.

Thread means that each thread will usually be read from a different position in the file. Nayveli, which will fill the OS to find the disk head behind and behind the different posts ... which will slow the I / O in practice, the OS will do many things to reduce it, but then Also, reading the data on different positions on the disk together is still bad for I / O throughput.


Comments

Popular posts from this blog

c# - SignalR: "Protocol error: Unknown transport." when navigating to hub -

c# - WPF Expander overlay used in ItemsControl -

android - how to get distance of 2 beacons and make a condtion base on that distance -