Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: FileChannel.tryLock() fails ...



First, I apologize for the double-posting....

That sample could have been cleaner...we just hacked together that sample based on what we do in our file-open logic.

You're right, Greg; we can't count on that locking call working. We were just surprised to run into this, because the code has been working in the field for a few years on several other platforms, and we've never run into a situation where it failed.

The general problem here is that the product is a programming language (business basic), so we need to do something intelligent if a user (developer) does this, and we can't create the lock:

OPEN (channel)"/Volumes/mycd/myfile.txt"

We don't know that the file is on a readonly filesystem; we just know that the user is opening a file. And when we open a file, we manage multiuser locking.

We've added an option to the file open to indicate that it's ok to ignore this IOException, should it occur. That takes care of the immediate problem for us.

Jim.

On 24-May-05, at 12:14 PM, Greg Guerin wrote:

Jim Douglas <email@hidden> wrote:


(Re-sent without a file attachment...are messages with attachments
blocked from the list?)


No, but the attachments are stripped.



Any suggestions would be very much appreciated...I'm lost.


Is your sample code supposed to be just a demonstration of the problem,
or an example of what you're trying to accomplish with locks?


I ask because your code falls back to opening a file read-only when it can't
open it R/W. But a file opened read-only doesn't need a lock, so if you're
going to fall back to R/O access, then you should also fall back to
omitting the lock. Or maybe I'm misunderstanding what the point is.



Your comment in the code:

// My understanding is that this should be true on most platforms, however, I
// cannot figure out how to upgrade a shared lock to exclusive, which would be
// needed on file lock is this was false.


See the API docs for FileLock.
<http://java.sun.com/j2se/1.4.2/docs/api/java/nio/channels/ FileLock.html>


They clearly explain that locks are platform-dependent. Locks are a thin
layer on whatever a platform offers natively, and you have to take what is
available on each platform. There is no universal portable semantics for
locks, and you should therefore write your lock-using programs to be
adaptable, rather than assuming that lock behavior is universal.


  -- GG


_______________________________________________ Do not post admin requests to the list. They will be ignored. Java-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Java-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden
References: 
 >Re: FileChannel.tryLock() fails ... (From: Greg Guerin <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.