I'm wanting to read the line of a .txt do the task, and move on to the next line.
To make the program quicker, I want to multi-thread so each thread tries a line.
The problem is, I don't want the thread 1 trying the same line as thread 2.
Any ideas?
I suggest you have one thread doing all the reading, then put the lines into a producer/consumer queue (e.g. a LinkedBlockingQueue
) - you can then have multiple threads servicing that queue as consumers.
You really don't want multiple threads performing IO here - even if you had multiple independent BufferedReaders
, if you're reading from traditional disks you don't want to end up seeking in multiple places. A producer/consumer queue separates the reading from the handling fairly simply - and makes it easier to test each part in isolation as well.
See more on this question at Stackoverflow