[jcifs] Hundreds of threads while listing directory

Sameer Mehta Sameer_Mehta at symantec.com
Thu Jun 3 10:07:28 MDT 2010

What is the value of jcifs.resolveOrder ? We use DFS in-house and I have
found that "LMHOSTS, WINS, BCAST, DNS" works for our setup. 




From: jcifs-bounces at lists.samba.org
[mailto:jcifs-bounces at lists.samba.org] On Behalf Of Peter Kossek
Sent: Thursday, June 03, 2010 2:01 AM
To: jcifs at lists.samba.org
Subject: [jcifs] Hundreds of threads while listing directory




I just started using jCIFS a couple of days before, but now I'm
experiencing some problems. My application throws an OOME while trying
to list the content of a directory.


The exception message:


Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError:
unable to create new native thread

        at java.lang.Thread.start0(Native Method)

        at java.lang.Thread.start(Thread.java:597)

        at jcifs.UniAddress.lookupServerOrWorkgroup(UniAddress.java:173)

        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.doFindFirstNext(SmbFile.java:2023)

        at jcifs.smb.SmbFile.doEnum(SmbFile.java:1731)

        at jcifs.smb.SmbFile.listFiles(SmbFile.java:1708)

        at jcifs.smb.SmbFile.listFiles(SmbFile.java:1641)

        at as_file.as_smb_lister.findFile(as_smb_lister.java:140)



The code for finding the file:


public static SmbFile[] findFile(SmbFile startFolder, String filename) {

        ArrayList<SmbFile> files = new ArrayList<SmbFile>();

        ArrayList<SmbFile> foldersToWalk = new ArrayList<SmbFile>();


        try {

            if (startFolder.isDirectory()) {



            while (foldersToWalk.size() > 0) {

                SmbFile lookInto = foldersToWalk.remove(0);

                System.out.println("walking " + lookInto.getPath());

                try {

                    SmbFile[] found = lookInto.listFiles(); // line 140

                    for (int i = 0; i < found.length; i++) {

                        if (found[i].getName().endsWith("/")) {


                        } else {

                            if (found[i].getName().equals(filename)) {





                } catch (SmbException ex) {




        } catch (SmbException ex) {



        SmbFile[] result = new SmbFile[files.size()];

        for (int i = 0; i < files.size(); i++) {

            result[i] = files.get(i);



        SmbFile[] found = new SmbFile[files.size()];

        for (int i = 0; i < files.size(); i++) {

            found[i] = files.get(i);


        return found;





The directory it's trying to list is
smb://KOSSEK/C$/Windows/winsxs/Backup/ which is known to contain lots of
files, 3256 files in this case.

I noticed that there is a peak of numbers of threads, up to more than
2000 threads (QueryThreads) at once that seem to bring the VM to its
limits. Maybe I made a mistake in my code that forces this massive
creation of threads, but I just can't find it. What can I do to fix


Thanks in advance for your help.


Best regards - Peter

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.samba.org/pipermail/jcifs/attachments/20100603/562387d4/attachment.html>

More information about the jCIFS mailing list