Article View: borland.public.jbuilder.java.language
Article #353Re: File Locking in IO classes
From: Vander
Date: Thu, 21 Apr 2005 07:39
Date: Thu, 21 Apr 2005 07:39
35 lines
2886 bytes
2886 bytes
Having in mind that RandomAccessFile (RAF) in fact does some file locking on the Win32 native packages, I walked from the simple question: "What can channel file-locking do for me what RAF doesn't already do for me?". After all it takes some extra time and resources to install code for channel file-locking. Some initial experiments in VM 1.4.2_06 have shown a somewhat funny picture. Exp A. Open a file in RAF and then try open it in external process (here MS-Word and Notepad) - Notepad (demanding only read-access) can retrieve the file's text - Word (demanding read/write-access) is broken with the correct message like "file in use by other process") Exp. B. Open a file in RAF, add a channel lock with "tryLock()" and then try open it in external process (here MS-Word and Notepad) - Notepad cannot retrieve the file's text (silent) - Word is broken with a confusing message, like "file not found etc. ..." Exp. C. Open a file in MS-Word (read/write-access) and then try open it in RAF - RAF is broken with "file not found" exception and the correct message like "file in use by other process". My first, provisorical conclusions from the above are: 1) both approaches (classic IO and channels) are performing some kind of file locking on the native file access layer 2) classic IO packages and channel locking are using different native resources or manipulations to acquire a file lock 3) RAF locks seem to allow other processes to discriminate between read and write access while channel locks seem to always block both. 4) If you want to block away ANY secondary access (including read access) you have to use channel locks 5) Channel locks may result in misleading error messages
Technical Details
Message-ID:
<426758a5@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!newshub.sdsu.edu!elnk-nf2-pas!elnk-pas-nf1!newsfeed.earthlink.net!pd7cy1no!shaw.ca!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<4264c9b6@newsgroups.borland.com> <xn0e16k112pcdb004-kdean@www.teamb.com> <42655400@newsgroups.borland.com> <xn0e18j7mw06c5003-kdean@www.teamb.com>Show Full Headers
Complete Article Headers
X-Google-Thread: f74b3,a6ef220bf23e44de X-Google-Attributes: gidf74b3,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Thu, 21 Apr 2005 09:39:11 +0200 From: Vander <874505@gmx.de> User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language Subject: Re: File Locking in IO classes References: <4264c9b6@newsgroups.borland.com> <xn0e16k112pcdb004-kdean@www.teamb.com> <42655400@newsgroups.borland.com> <xn0e18j7mw06c5003-kdean@www.teamb.com> In-Reply-To: <xn0e18j7mw06c5003-kdean@www.teamb.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 217.232.185.241 Message-ID: <426758a5@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1114069157 217.232.185.241 (21 Apr 2005 00:39:17 -0800) Lines: 36 Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!newshub.sdsu.edu!elnk-nf2-pas!elnk-pas-nf1!newsfeed.earthlink.net!pd7cy1no!shaw.ca!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail