Re: Problem to write on SmbFile while trying to write by multithreading on java.
Michael B Allen <[email protected]> Thu, 2 Aug 2012 13:35:35 -0400
| Newsgroups | gmane.network.samba.java |
|---|---|
| Message-ID | <CAGMFw4h+4Kb3=eEzCxDCuH-LSZ2j5rSjSEHrB5kohtyiyuHG0A@mail.gmail.com> |
On Tue, Jul 31, 2012 at 7:36 AM, mrashid <[email protected]> wrote: > Hi All, > > I am facing some problems while writing on a particular SmbFile located at a > shared location through SmbFileOutputStream. > It seems pretty cool while doing the above job using single thread, but > problem happens while attempting to write on that single SmbFile using > multithread, some data is missing on SmbFile and the whole channel became > slow more and more rather than single thread instead of being faster. I'm > using different SmbFile objects to write on while using multithreading > feature but nothing fruitful comes out. Hi Rasheed, You cannot operate on the same SmbFile object using multiple threads. It is not thread safe. Each thread has to use a separate SmbFile object. And note that you need to be careful about writing to the same file with multiple threads (using JCIFS or anything else). Depending on the flags used (append, shareAccess, etc), I don't know how the server would handle that in each case. If you're doing something like appending to a log file from multiple threads that should at least be thread safe. But you should make sure that you write the entire log entry with one call to write(). And you might need to open, write and close the file for each write. Otherwise, if you want to keep the OutputStream open for multiple writes, I would test that thoroughly with a test program that used 10 threads to write hundreds of times per second, let it run for 10 minutes and verify that it works and that the file contains the expected data. I suspect it will work and it should be very fast. Nothing should be "slow". If it does get slower then something is serializing the writes. Mike -- Michael B Allen Java Active Directory Integration http://www.ioplex.com/