[jcifs] Davenport Locking

Chris McEniry cmceniry at mit.edu
Tue Mar 2 15:48:13 GMT 2004

I've been working on getting locking working in Davenport, and I've 
gotten it most of the way there for single file lock requests, but I've 
run into a problem holding the lock that I'm hoping someone here may be 
able to shed some light on.

Basically, my methodolgy is this:

.) Keep a servlet context level object that contain holds Locks(which 
have the webdav info - token, timeout, etc - and the smb info - a 
SmbFile and an SmbRandomAccessFile).  Locks are stored in a hash keyed 
on the token.
.) When a LOCK request comes in, it attempts to create a SmbFile with 
shareAccess = FILE_SHARE_READ, and to open a SmbRandomAccessFile, and 
keeps those around.
.) When another method comes in with an "If" header, it looks up the 
lock in the map and returns the SmbFile which is stored in the lock.
.) Locks are released explicitly when an UNLOCK comes in, or when the 
timeout expires(there's a cleanup thread running in the background that 
sweeps through the hash every 5 seconds and removes locks which have 

And by watching part of it, it appears that the SmbFile is opening and 
getting a lock on the SMB server(samba 3.0.2 fyi), but after about 30 
seconds or a minute, the lock disappears.  Davenport is none the wiser 
to this and goes along it's merry way, but I am able to open and get a 
lock on the file when accessing it directly(by mapping to the samba 
server from my desktop).

So, my questions are: Does jCIFS close connections on a regular basis or 
am I missing something? and, when using shareAccess for locking, does 
the SmbFile object hold the lock or only the real file access 
objects(SmbFileRandomAccess, SmbFileInputStream, SmbFileOutputStream, etc)?

If it helps, a diff from 0.9.8 is availble at


(I have other questions stemming from the rest of this - permissioning 
and who to show what locks to etc -, but I'll save those for another 


More information about the jcifs mailing list