클라이언트에서 들어오는 POST로 로그 파일에 쓰는 프로세스 (실제로 웹 서버)가 있습니다. 이 시간을 잘 99 % 작동하지만 때때로 라인이 I에 의해 읽어라인이 완료되기 전에 BufferedReader readLine
BufferedReader reader = new BufferedReader(new FileReader(logFilePath));
String line = null;
while (true)
{
if ((line = reader.readLine()) != null)
{
if (firstLine == null) firstLine = line;
processLine(line);
continue;
}
try
{
Thread.sleep(sleepTime);
long ts = System.currentTimeMillis();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
}
: 다음
나는 루프에서 (꼬리 -f)과 같은 로그 파일을 읽고 별도의 프로세스를 BufferedReader.readLine은 완전한 행이 아닙니다. 나는 작가 (웹 서버)가 파일의 모든 바이트를 아직 플러시하지 않았기 때문이라고 생각한다.
이 문제를 수정하거나 해결할 제안이 있습니까? 고마워요!
라인이 완료되지 않았을 때 감지 할 패턴이 있습니까? – VirtualTroll
그냥 빠른 포인터 :'while (true) ... break'을 사용할 필요가 없습니다. 변수를 사용하여 계속해야하는지 확인할 수 있습니다. – Viruzzo
이게 도움이 될 것 같습니다. http://docs.oracle.com/javase/1.4.2/docs/api/java/io/FileDescriptor.html#sync() – nullpotent