harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stepan Mishura" <stepan.mish...@gmail.com>
Subject Re: [classlib][logging] A non bug difference from RI?
Date Fri, 01 Sep 2006 11:30:53 GMT
On 9/1/06, Paulex Yang wrote:
>
> Stepan Mishura wrote:
> > Andrew, thanks for the test. But working test doesn't mean that there
> > is no
> > bug :-)
> >
> > AFAIK in our case an operation on file (if file is not exist  - create
> > file)
> > should be atomic. And it looks like Harmony implementation doesn't do in
> > atomic way.(see FileHandler.initOutputFiles() method)
> Seems there is a bug in the FileHandler.initOutputFiles(), in Ln. 232,
> if the FileLock isn't held, the FileOutputStream should be closed before
> continue.
>
> <code>
>                lock = channel.tryLock();
>                if (null == lock) {
>                   //the FileChannel(or FileOutputStream) should be
> closed here
>                    continue;
>                }
> </code>


BTW, why FileNotFoundException is re-thrown  in Ln. 223 ? IMO, try-catch
block should be deleted.

                try {
                    fileStream = new FileOutputStream(fileName, append);
                    channel = fileStream.getChannel();
                } catch(FileNotFoundException e){
                    //invalid path name, throw exception
                    throw e;
                }


But I didn't catch up what's the "atomic" means here, do you mean the
> tryLock() is not atomic or sth.? If so, any other solutions for Java
> codes? Otherwise, I think current implementation is fine, if two process
> try to open same log file at same time, only one process can get the
> lock by tryLock(), and the other will close the FileOutputStream then
> continue to try another log file name, anything I missed?


I was confused by gaps in code between File.exists(), new FileOutputStream()
and FileChannel.tryLock().

For example, I've tried to emulate the following situation:
A process VM_1 is up to lock a created file (Ln.230) and in this time a
process VM_2 found out that the file exists and deleted it (Ln.213). My
current result is that the file is locked successfully but may be I
incorrectly emulated situation. I'm going to continue experimenting and let
you know if it is possible to create reproducible files conflict.

Thanks,
Stepan Mishura
Intel Middleware Products Division

------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message