[jcifs] OutOfMemoryError unable to create new native thread

Michael B Allen ioplex at gmail.com
Sat Mar 6 23:24:51 MST 2010


Hi Peter,

The whole point of the QueryThread is to allow simultaneous lookups
such that the first valid response is used immediately without
waiting. So by adding join you basically completely defeat the purpose
of using QueryThreads at all. You might as well just dump the
QueryThreads entirely and perform to synchronous lookups.

First, try playing with the name service properties. Try setting
jcifs.resolveOrder=DNS. I think that might stop the NetBIOS lookups
entirely. Of course you'll then need to use only fully qualified DNS
hostnames.

Otherwise, you'll need to look at why these lookups are being
generated at such a high frequency in the first place. You must be
using an awful lot of threads if you eventually end up spawing 1900
lookups in which case you might want to analyze and determine if using
that many threads is really increasing overall throughput. Or prevent
all of the threads from starting at the same time so that the result
of the lookups have a chance to be cached.

Regarding the cache, if it turns out that increasing
jcifs.netbios.cachePolicy reduces the frequency of the lookups, then
that is actually a good solution. These names do not change
frequently. The default value is low only because in almost all cases
it doesn't need to be higher. It's only when someone is trying to do
100 lookups at the same exact instant that it matters. This is why we
provide for changing these properties.

Mike

On Fri, Mar 5, 2010 at 2:06 PM, Peter <peter_zavadsky at symantec.com> wrote:
> It seems I have a fix, which works on my machine. At the end I was getting the
> issue even when the jcifs.netbios.cahePolicy had the default value.
>
> The fix below adds a method waitForQueryThreads into the lookupServerOrWorkGroup
> method in UniAddress.java. The point is to wait for the query threads, also
> interrupt them in order to speed up the join. The query threads might be either
> in wait or I/O blocked.
>
> Please, let me know, if you can reproduce the problem, or if the fix is
> applicable.
>
> Thanks,
> -Peter
>
> Snipped from UniAddress.java:
>
>    static NbtAddress lookupServerOrWorkgroup( String name, InetAddress svr )
>                                                    throws UnknownHostException {
>        Sem sem = new Sem( 2 );
>        int type = NbtAddress.isWINS( svr ) ? 0x1b : 0x1d;
>
>        QueryThread q1x = new QueryThread( sem, name, type, null, svr , 1);
>        QueryThread q20 = new QueryThread( sem, name, 0x20, null, svr , 2);
>        q1x.setDaemon( true );
>        q20.setDaemon( true );
>        try {
>            synchronized( sem ) {
>                q1x.start();
>                q20.start();
>
>                while( sem.count > 0 && q1x.ans == null && q20.ans == null ) {
>                    sem.wait();
>                }
>            }
>        } catch( InterruptedException ie ) {
>            throw new UnknownHostException( name );
>        }
>
>            waitForQueryThreads(q1x, q20);
>
>            if( q1x.ans != null ) {
>            return q1x.ans;
>        } else if( q20.ans != null ) {
>            return q20.ans;
>        } else {
>            throw q1x.uhe;
>        }
>    }
>
>        private static void waitForQueryThreads(QueryThread q1x, QueryThread
> q20)
>        {
>                interruptThreadSafely(q1x);
>                joinThread(q1x);
>                interruptThreadSafely(q20);
>                joinThread(q20);
>        }
>
>        private static void interruptThreadSafely(QueryThread thread)
>        {
>                try
>                {
>                        thread.interrupt();
>                }
>                catch(SecurityException e)
>                {
>                        e.printStackTrace();
>                }
>        }
>
>        private static void joinThread(Thread thread)
>        {
>                try
>            {
>                    thread.join();
>            }
>            catch (InterruptedException e)
>                {
>                        e.printStackTrace();
>                }
>        }
>
>
>
>
>
>



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


More information about the jCIFS mailing list