当前位置: 动力学知识库 > 问答 > 编程问答 >

java - How to lock if condition until both conditions are true?

问题描述:

I have a program which parses last one hour data from a log file and keeps it in another file. I need to keep the condition running until the program finds one hour data. The one hour data will be written inside the log file by a server.

How do I keep the condition running until it finds one hour data?

ReversedLinesFileReader reverse= new ReversedLinesFileReader(file);

PrintWriter writer= new PrintWriter(f2+"/"+fileName1); ;

String line;

while ((line = reverse.readLine()) != null) {

List<String> stringList = Arrays.asList(line);

if(line.contains(Constants.SPEEDO)) {

timeFromLine = getTimeFromLine(line);

timeFromSystem= getSystemTime();

timeGap= propertiesReader.getPropertyValue("timeGap");

format.setTimeZone(TimeZone.getTimeZone("GMT"));

timeLine= format.parse(timeFromLine);

timeSystem=format.parse(timeFromSystem);

timeGapDate=format.parse(timeGap);

startTimeLong=timeSystem.getTime();

timeGapLong=timeGapDate.getTime();

endTimeLong=startTimeLong-timeGapLong;

Date d= new Date(endTimeLong);

endTimeString= format.format(d);

endTimeDate1=format.parse(endTimeString);

if(timeLine.before(timeSystem)&&timeLine.after(endTimeDate1)) {

writer.println(line);

}

}

}

writer.close();

reverse.close();

网友答案:

Thanks to @Thomas, I used polling interval to run the code in an interval. You can find the full sample program in this link

final long pollingInterval = 5000

分享给朋友:
您可能感兴趣的文章:
随机阅读: