[jcifs] Strange issue with SmbFileInputStream

Michael B Allen ioplex at gmail.com
Thu Jan 28 08:59:52 MST 2010


On Thu, Jan 28, 2010 at 8:52 AM, René Liebmann
<rene_liebmann at datamatics.de> wrote:
> Hi Mike,
>
> Thank you for your response. Usually I have wrapped my Java app with an EXE.
> I have changed this now and the behavior is a bit different, but the result
> seems to be the same. The reason is an OutOfMemoryError, which in fact
> should not be, as I use the options -Xms400m -Xmx400m and during the time
> when it hangs my app has just 100 M occupied as per TaskManager. I also
> increased the memory to 800m. Then 2 or 3 files more are getting copied and
> it hangs again. Please find here the dump, which came up in the console:
>
> C:\tmp>java -Xms400m -Xmx400m com.rli.fsi.gui.FileSystemInventory
> Exception in thread "pool-1-thread-2" java.lang.OutOfMemoryError: unable to
> crea
> te new native thread
>        at java.lang.Thread.start0(Native Method)
>        at java.lang.Thread.start(Unknown Source)
>        at jcifs.UniAddress.lookupServerOrWorkgroup(UniAddress.java:172)
>        at jcifs.UniAddress.getAllByName(UniAddress.java:290)
>        at jcifs.UniAddress.getByName(UniAddress.java:245)
>        at jcifs.smb.Dfs.getTrustedDomains(Dfs.java:62)
>        at jcifs.smb.Dfs.resolve(Dfs.java:167)
>        at jcifs.smb.SmbFile.resolveDfs(SmbFile.java:666)
>        at jcifs.smb.SmbFile.send(SmbFile.java:768)
>        at jcifs.smb.SmbFile.close(SmbFile.java:1009)
>        at jcifs.smb.SmbFile.close(SmbFile.java:1015)
>        at jcifs.smb.SmbFile.close(SmbFile.java:1019)
>        at jcifs.smb.SmbFileInputStream.close(SmbFileInputStream.java:104)


Hi Rene,

This is not a thread dump, it is just a stack trace. Your stack trace
shows two things - 1 the problem is that you are running out of memory
and 2 JCIFS is somewhat stupidly trying to do a DFS lookup from a call
to close().

I have made a note of 2 but I do not think it is related to 1 and, in
general, I rather doubt JCIFS has anything to do with your
OutOfMemoryError. It probably just seems like it is because JCIFS is
trying to create a new Thread to do a name service lookup and that
requires a large chunk of memory. It is more likely that the code that
you are working on that uses JCIFS is actually leaking objects or
wasting reasources in some way.

If your application needs -Xms400m -Xmx400m to run, I think you need
to back up and find a JVM profiler and look at how many objects of
each type are being created and then reason about how many there
should be of each type. I have a feeling you'll find that you have an
object-sink somewhere (aka Java memory leak).

Mike

> -----Ursprüngliche Nachricht-----
> Von: Michael B Allen [mailto:ioplex at gmail.com]
> Gesendet: Mittwoch, 27. Januar 2010 18:05
> An: Rene Liebmann
> Cc: jcifs at lists.samba.org
> Betreff: Re: [jcifs] Strange issue with SmbFileInputStream
>
> Hi Rene,
>
> Wait a while to make sure it is really hanging. If it does not respond
> after a few minutes, get a thread-dump using Ctrl-Break on Windows or
> Ctrl-\ on Unix in a console. That will show you exactly where it's
> stuck.
>
> Mike
>
> On Wed, Jan 27, 2010 at 11:35 AM, René Liebmann
> <rene_liebmann at datamatics.de> wrote:
>> Hi all,
>>
>>
>>
>> I have a small function which I use to copy a remote file to my local
>> machine. On almost all environments (Win XP Home) this works fine, but on
> a
>> Windows 2003 Server environment it does only copy a small portion of a
> file
>> e.g. if the file is 6 MB large it copies 248 kB. Then it seems that it
> never
>> leaves the while block and my program hangs. It does not throw any
>> exception. What am I doing wrong?
>>
>>
>>
>> private void copySmbFileTo(SmbFile f, String location) throws IOException
> {
>>
>>         logger.debug(name + " enter function copySmbFileTo
> "+f.getUncPath()
>> + " to "+location);
>>
>>
>>
>>         SmbFileInputStream istr = null;
>>
>>         OutputStream ostr = null;
>>
>>         try {  // 1
>>
>>             istr = new SmbFileInputStream(f);
>>
>>             ostr = new FileOutputStream(location);
>>
>>             byte[] buf1 = new byte[1024];
>>
>>             int len1;
>>
>>             while((len1 = istr.read(buf1)) > 0){
>>
>>                 ostr.write(buf1, 0, len1);
>>
>>             }
>>
>>             ostr.flush();
>>
>>         } catch(Exception ex){
>>
>>             logger.error("", ex);
>>
>>         } finally{
>>
>>           try { // 2
>>
>>             if(istr!=null)  istr.close();
>>
>>             if(ostr!=null)  ostr.close();
>>
>>           } catch(Exception ex){
>>
>>               logger.error("Major Error Releasing Streams:", ex);
>>
>>
>>
>>           } // End try catch number 2
>>
>>         } // End try catch finally number 1
>>
>>         logger.debug(name + " leave function copySmbFileTo");
>>
>>
>>
>>     }
>>
>>
>>
>> Thanks for your ideas in advance
>>
>>
>>
>> René
>>
>>
>
>
>
> --
> Michael B Allen
> Java Active Directory Integration
> http://www.ioplex.com/
>
>



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


More information about the jCIFS mailing list