0

I'm creating an Android app which is going to read very large files, with about 1.000 to 40.000 lines, which takes quite a bit of time with a single loop. Therefore, I'm trying to create a multithreaded reader, which creates multiple threads, and each of them reads a specific part of the file, and then it puts all the small parts together in one big array or String.

I'm using a BufferedReader which loops through each line in the file, and store the line count.
Each time the loop run, I check if lineNumber % LINES_PER_READER == 0 is true. If it is, I create a new reader thread, which should read the next LINES_PER_THREAD-number of lines in the file.

I wonder (because the files can be huge) if I can copy or clone the BufferedReader in any way, so that the new reader thread can just start reading from the line where it was created, because I already have a loop which is reading that line, instead of creating a new BufferedReader, read each line until I get to the specified line and then start reading the actual values.

user229044
  • 232,980
  • 40
  • 330
  • 338
Daniel Kvist
  • 3,032
  • 5
  • 26
  • 51
  • possible duplicate of [How can I make a copy of a BufferedReader?](http://stackoverflow.com/questions/12107049/how-can-i-make-a-copy-of-a-bufferedreader) – Andy Turner Mar 18 '15 at 17:21
  • 1
    Side note: Are you sure the bottleneck is processing time and not IO bandwidth? – dhke Mar 18 '15 at 17:31

1 Answers1

1

Don't clone the BufferedReader. It will create trouble. Just send batches of lines to the individual processing threads.

Bram
  • 479
  • 2
  • 10
  • I'll try this. It might be the IO bandwidth which is the problem. Then, this might not work... – Daniel Kvist Mar 18 '15 at 19:03
  • If IO bandwidth is the problem, this wouldn't help, but not hurt much. Having multiple BufferedReaders would hurt more then. – Bram Mar 18 '15 at 19:32
  • Do you have any other suggestion then, if the IO bandwidth is the problem? – Daniel Kvist Mar 18 '15 at 19:33
  • No, if IO bandwidth is the issue, the best you can do is ensure you read the file no more than once, sequentially. – Bram Mar 18 '15 at 19:39