I'm trying to parse a log file. I need help in checking the time difference between a request and response. Essentially number of requests that took more than 10 seconds. Following is a sample excerpt from the file:
16/08/29-03:20:39.538 << 1250 REQUEST COUNTER="1"
16/08/29-03:20:39.542 << 1250 REQUEST COUNTER="2"
16/08/29-03:20:39.656 >> 2250 RESPONSE COUNTER="1"
16/08/29-03:20:39.655 >> 2250 RESPONSE COUNTER="2"
This file can have around 3 million records. I'm thinking of reading it using a BufferedReader, reading a line then checking to see if "COUNTER" is present in the line, storing request time and the value of counter, then searching the entire file for the same counter value to get the response time and then checking the difference.
I need help in storing the time and checking the difference. Also, is there any better approach?
BufferedReader reader = new BufferedReader(new FileReader(new File(fileName)));
String line;
while((line = reader.readLine()) != null) {
if(line.contains("COUNTER")) {
String[] tokens = line.split("\\s+");
Date date = new SimpleDateFormat("yy/mm/dd-HH:mm:ss.SSS").parse("16/08/29-12:42:48.167");
//this is not storing the correct value
}