[jcifs] jCIFS Thread Safety

Michael B Allen ioplex at gmail.com
Mon Jan 6 00:02:35 MST 2014


On Mon, Nov 25, 2013 at 3:02 PM, Aravindan Thulasinathan
<Aravindan_Thulasinat at symantec.com> wrote:
> Hello,
>     This might be a very simple question. In the product that I work for,
> there is some historic data documented which claims, "jCIFS is not thread
> safe". But, with the jCIFS implementation today, I see that jCIFS indeed
> supports multi-threaded callers. I just wanted to confirm the same with
> folks here. As long as each thread creates a separate SMBFile object (for
> different files of course), it should work without any issues right?

Hi Aravindan,

JCIFS is absolutely 100% thread-safe and it was designed that way from day zero.

But just because a library is "thread-safe" does not mean you can call
an arbitrary method of some object with multiple threads concurrently.

For example, would you create a java.io.File object and then have
multiple threads call mkdir() on it concurrently? No way. Does that
mean java.io.File is not thread-safe? No. It just means that each
thread has to create it's own java.io.File.

Thread safety is usually implemented relative to some context data
where thread-specific state can be stored. In the case of JCIFS, the
"context object" is simply each SmbFile object (or
SmbFileOutputStream, etc).

Note that there are some elaborate "crawler" examples in the JCIFS
package. The most sophisticated ones create a breadth-first-search
list of SmbFile objects and have multiple threads process the list.
Meaning it actually does use multiple threads with the same SmbFile
object. But it uses extra locking to ensure that no two threads work
on the same SmbFile object concurrently.

Mike

-- 
Michael B Allen
Java Active Directory Integration
http://www.ioplex.com/


More information about the jCIFS mailing list