Hello encountered a problem. I will try to describe it in General terms. I need to read data FROM the file as quickly as possible .csv and process them. There are no problems with processing. But how to make multithreading in reading. I see several options. The order of data is not important.
- Split the file into several parts and read it at the same time.
- I've heard that you can make a BufferReader and sync it, but I couldn't find a working example.
My code
Instant start = Instant.now();
int i = 0;
try (BufferedReader reader = new BufferedReader(new FileReader("lng.csv"))) {
String line = reader.readLine();
while (line != null && i < 150000) {
System.out.println(i + ") " + line);
// read next line
line = reader.readLine();
//my data processing
if (verifyLine(line)) {
groupAdder(line);
}
else{
System.out.println("Wrong line: "+ line);
}
i++;
}
} catch (IOException e) {
e.printStackTrace();
}
Instant end = Instant.now();
System.out.println(Duration.between(start, end));
I will be happy with your solutions to this problem. I will also be very happy to look at the code examples