new FileWriter hangs



Hello. I have a java program where I repeatedly write to a log file,
and at random times (typically after 100.000 writes or so) the program
just hangs. I've found that this happens while executing a 'new
FileWriter' command. I only have one thread writing to the file,
there's no exceptions thrown or anything, the CPU usage just goes to
zero and then nothing happens at all. Meanwhile, the log file remains
globally locked for writing, i.e. I can't delete it in Explorer without
first killing my java program. I experience this bug on a dual xeon
processor machine, running Windows Server 2003 and java version
1.5.0_04.

Here's the code, it hangs while executing the very first line of code:

FileWriter fileWriter = new FileWriter("log.txt", true);
BufferedWriter buffWriter = new BufferedWriter(fileWriter);
buffWriter.write(message);
buffWriter.newLine();
buffWriter.close();

If anyone has any ideas why this happens, please let me know. I guess
in this case I could leave the file open at all times to avoid this,
but I would be more interested to know the cause of it.

Mattias

.



Relevant Pages

  • Re: Logrotate is a pain
    ... >> I'm using logrotate to backup my apache log files and a custom log ... when logrotate rotates the logfile of my java program it ... > seems to be that your application opens a file and keeps writing to it. ... > Alternatively, if your application writes to the log file infrequently, ...
    (comp.os.linux.misc)
  • Re: new FileWriter hangs
    ... mattias wrote: ... I have a java program where I repeatedly write to a log file, ... > and at random times the program ...
    (comp.lang.java.programmer)
  • Re: Logrotate is a pain
    ... >>to the original log file. ... > file if it is writing straight to it (or signal syslog if it is talking ... The OP's Java program would need to be modified to ...
    (comp.os.linux.misc)
  • Re: Mystery icon on desktop
    ... A log file, to be excact, with what to me ... looks like JRE giving up on some java program, ...
    (microsoft.public.windowsxp.general)
  • Re: VB: File Hook
    ... >There is a 3rd party program that writes to a log file at random times. ... >After searching around i came across a program called API monitor that ...
    (microsoft.public.vb.winapi)