[jcifs] OutOfMemoryError unable to create new native thread

Peter peter_zavadsky at symantec.com
Fri Mar 5 12:06:53 MST 2010


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();
		}
	}







More information about the jCIFS mailing list