Submitted On 08-DEC-1997
cgrau1
We created a LockFile class that created and locked
a given file using native C methods. Problem is, everyone has to remember
to use this interface.
Submitted On 03-JUL-1998
fancellu
After JDK 1.2? It is not a cosmetic extra,
it is very important. Most OS have file locking,
or they wouldn't work, so what's so hard about
doing it? Has it even been tried yet?
Submitted On 16-AUG-1998
glenng
you've got to be kidding! there's no support for
exclusive write access to a file until after
jdk 1.2!!
Submitted On 18-AUG-1998
JWilliams
I need something similar but in my case I need to support multiple concurrent
reader and to exclude writers while the readers are active.
the Java spec seems does not define the behavior very precisely. I guess I will
have to test different platforms, and Java VMs etc... to figure out what
policies are implemented, and implement inefficient workarounds were needed -
yuk.
Submitted On 03-DEC-1998
jalvingh
No support for locking till after 1.2!? That means that easy multi-user support
goes down the drain!
Submitted On 19-FEB-1999
alanD
This is a truly fundamental problem - should be very
high priority.
Submitted On 27-APR-1999
petewilliams
Like everyone else who is trying to implement a database product, we need this
capability. For us, an alternative solution would be if the server program
could find out whether there were any other instances of itself running, and
refuse to start if there were. Otherwise, we will have to implement a
"dang fool lock file", too!
Submitted On 21-FEB-2000
jordanz
I was very very surprised that exclusive locking isn't
supported in Java. This is a very serious omission that
will require us to write native code. We feel that this
should be a very high priority for Sun.
Submitted On 08-MAR-2000
werezak
Unbelievable! If someone is writing a large file and I am
polling to see if the file has arrived, I have no way of
knowing if the file has completed writing because Java
cannot detect that someone else has an exclusive write
lock. The 'File' class should be enhanced to provide a
canWriteExclusive() in addition to canWrite() to indicate
this state. This should be a high priority.
Submitted On 23-MAY-2000
bsutton_java
This is an urgent problem that needs to be resolved ASAP.
Not only do we need exclusive locking semantics but we also
need all of the standard locking semantics. This should
include byte range locking, shared readers (which excludes
all writers) etc.
Submitted On 16-SEP-2000
mdenty
Here we are on JDK 1.3 and this is not fixed. I don't think
this should be a RFE, it's a *BUG*. I had tool a look on
the sources of the JVM 1.3. it will be so easy for Sun to
do this (the function are written but not interfaced with
Java side) !
I have tried to write a natice an java classes to use
_sopen instead of open. (soon [10/2000] on www.denty.org)
Should be very high priority for Sun and only one hour of
work to do this !
Submitted On 08-DEC-2000
mdenty
You can download a patch for this (Win32) at
download.denty.org
Submitted On 11-JAN-2001
ScottAllen
For our project, we're going to try two approaches, one of
which uses RMI, and the other of which uses CORBA. Doesn't
this seem a little extreme for such a seemingly simple
concept as file-locking?
Submitted On 26-JAN-2001
werezak
Too bad this isn't fixed yet :(. I wrote a NT native
method to handle it if anyone is interested.
Submitted On 31-JAN-2001
fancellu
Over 2 years later after my first comment, still no change.
Sun are soooo arrogant.
I wonder if we'll get to 1.4 and still no fix.
It wouldn't surprise me.
Sun know NOTHING about real world apps.
Submitted On 11-FEB-2001
dmbdmb
While we're at it, we need range locking as well.
Submitted On 22-FEB-2001
cube729
There's a problem with the "dang fool lock file."
That file needs to be locked as well.
Submitted On 26-FEB-2001
xiaolinq
It should be a bug instead of rfe. Because the "atomic-file-create
method in JDK 1.2 release (RFE 4130498)" is not atomic. Please fix this
ASAP
Submitted On 16-MAR-2001
tcole
If we can't have explicit file locking, why not AT THE VERY
LEAST implement a way to set a File's write permission on
from within the API. You can turn it off (File.setReadOnly
()) but you cannot turn it back on.
I must admit I love the passive tone of the original
evaluation. "This would be very difficult because...." I'd
like them to try to tell my Boss that same line and keep
their job.
Submitted On 20-MAR-2001
mdenty
My Java apps MUST see the locks put by other Windows apps.
Merlin will not help me ? !!!!
Submitted On 17-APR-2001
mthornton
To emulate advisory whole file locking with the Windows
API, just lock a region (far) beyond the end of the file.
For Windows 9x lock the byte at 2^32 - 1, for Windows
NT/2000 lock the byte at 2^64 - 1. While this may not be
perfect (it fails for files at the limit), in practice it
is likely to be adequate.
To implement mandatory locking range locking, add a new
class of RandomAccessFile which allows at most a single
range to be locked (at any one time). Any attempt to write
without a lock or outside of the locked region can be
easily blocked without a system call (all it takes is a
couple of comparisons). It doesn't matter if the underlying
system lock semantics are mandatory or not. It wouldn't be
hard to extend this to multiple lock regions. This is more
restrictive than the usual system API only in that you MUST
acquire a lock before writing to this type of file. I don't
see this as a serious problem. If you must attempt to write
to the file without having a lock, then just create an
ordinary RandomAccessFile on the same handle (which then
won't be checked).
Submitted On 15-MAY-2001
juancn
WORKAROUND
Why not use a locking file, something like:
public boolean lock() {
try {
File lock = new File(...); //Lock file
if(lock.createNewFile()) {
lock.deleteFileOnExit();
return true;
}
} catch(IOException ignore) {}
return false;
}
The code above works since JDK 1.2, if you are using an
earlier
vesrion, you could use File.mkdir() instead of
File.createNewFile()
That is not a perfect approach, beacuse an unaware proccess
might still break your locking semantics, but for most of
the cases it works.
Submitted On 15-MAY-2001
juancn
Sorry, it works for *all* the cases, I should have said,
that for most cases is enough.
Submitted On 16-MAY-2001
jdkament
Please don't assume the lowest common denominator (advisory
locking)! If the problem is deciding whether to do
mandatory or advisory locking, why not do both? It would
seem that, for apps which need exclusivity, mandatory
locking is always the better (and stronger) choice.
However, compatibility with the O/S might be of greater
important for some applications. So, write the locking
mechanism such that the request to lock can specify wether
mandatory, advisory or O/S default locking is desired.
Have a return code (or other form of query) which indicates
which was used. This solves the problem of what to do. If
doing all of the above is too much work, the initial
implementation could just do O/S default, which should be
easy. Since it would be possible to determine what method
was being used, this should be acceptable.
Submitted On 18-MAY-2001
mthornton
As the system backup application does not respect lock file
schemes (at least for Windows), any files 'locked' in this
way are likely to be recorded with inconsistent content.
This is completely unacceptable.
Submitted On 01-JUN-2001
abies
In 1.4 beta there is a method
java.nio.channels.FileChannel.lock().
I think it does exactly what people want.
Submitted On 03-JUL-2001
johnny_hifive
I have implemented a file locking scheme, and my biggest
current problem is what to do with a 'power off' scenario
which seems to happen with my trigger happy ctl-alt-del
customers. I created a file as suggested, but then it can
get left around and detected by the next java program at
startup leaving the file permanently locked. I'm not sure
there is a fix for that other than taking up resources that
windows / unix force to be freed up when the JVM is gone,
ie ports. Aside from user intervention (which is annoying
and shouldn't be necessary) I can't see a way around
this ... and would hope that Sun includes the power off
scenario in their implementation.
Submitted On 16-JUL-2001
wrd02
I've just been sent an email by some bot saying that this bug is now closed (and all the votes have been freed). But nothing has been done to fix it (it's still open and marked as in progress). WTF is going on? Suggest that everybody who hasn't been forced to give up in disgust (I have, but hope springs eternal) and implement their own native code should come back here and reassert their vote.
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|