R
Rhino
I have a variety of applications that need to be able to write diagnostics
to the same flat file. While there won't be that many situations where any
of these applications are running concurrently, it could happen. What is the
best way to write my applications to handle the case where Program A wants
to write to the flat file while Program B is already writing to it?
Am I safe in assuming that there is no safe way to have multiple Java
programs simultaneously writing to the same flat file? If I am, then am I
correct in assuming that each program that wants to write to the flat file
needs to first verify that the file is not already in use? If so, what is
the correct way to determine if some other program is writing to a file? I
don't see anything in the File class that indicates if a file is in use,
unless perhaps canRead() does that; the API is very vague on that so I'm not
sure if canRead() is actually reporting on whether a file is already in use.
Now, assuming that I'm right about having to verify that no other program is
using the file, what should my program do if it finds that the file is in
use when it wants to write to it? Should the program that wants the file be
forced to exit? Or should it go on about its work and simply not try to
write to the file after all?
How do loggers handle this situation? What happens if two concurrent
applications want to write to the same log file at the same time?
--
Rhino
---
rhino1 AT sympatico DOT ca
"There are two ways of constructing a software design. One way is to make it
so simple that there are obviously no deficiencies. And the other way is to
make it so complicated that there are no obvious deficiencies." - C.A.R.
Hoare
to the same flat file. While there won't be that many situations where any
of these applications are running concurrently, it could happen. What is the
best way to write my applications to handle the case where Program A wants
to write to the flat file while Program B is already writing to it?
Am I safe in assuming that there is no safe way to have multiple Java
programs simultaneously writing to the same flat file? If I am, then am I
correct in assuming that each program that wants to write to the flat file
needs to first verify that the file is not already in use? If so, what is
the correct way to determine if some other program is writing to a file? I
don't see anything in the File class that indicates if a file is in use,
unless perhaps canRead() does that; the API is very vague on that so I'm not
sure if canRead() is actually reporting on whether a file is already in use.
Now, assuming that I'm right about having to verify that no other program is
using the file, what should my program do if it finds that the file is in
use when it wants to write to it? Should the program that wants the file be
forced to exit? Or should it go on about its work and simply not try to
write to the file after all?
How do loggers handle this situation? What happens if two concurrent
applications want to write to the same log file at the same time?
--
Rhino
---
rhino1 AT sympatico DOT ca
"There are two ways of constructing a software design. One way is to make it
so simple that there are obviously no deficiencies. And the other way is to
make it so complicated that there are no obvious deficiencies." - C.A.R.
Hoare