[jcifs] OutOfMemoryError unable to create new native thread

Peter peter_zavadsky at symantec.com
Fri Mar 5 11:11:36 MST 2010


Hi,

This has been already here. However, I think I might have found the culprit.

Here is a test case, which reproduces the issue (at least on my machine). My
configuration: Windows Server 2008 R2 64 bit, Java 1.6.0_05 (32 bit!), JCIFS
1.3.13.

It seems that when there are a lot of consecutive requests, the previous
QueryThread instances don't die out, therefore the number of the threads
increases until it reaches the limit of the process resources (on my machine
it is ~1900 threads).

Note you can try to workaround this problem by increasing
"jcifs.netbios.cachePolicy" value.

I tried one fix, i.e. to use join method on the QueryThreads in the
lookupServerOrWorkgroup method. That fixes the problem, however it also degrades
the performance terribly.
A better fix is needed.

It seems that the problem is that there are created new QueryThreads per each
request, which consumes a lot of resources. Much better would be to reuse the
dedicated QueryTheads as queues.

Thanks,
-Peter


UniAddressTest.java:

package jcifs;

import org.junit.Test;
import java.net.UnknownHostException;
import java.util.Map;
import jcifs.netbios.NbtAddress;

public class UniAddressTest
{
	static
	{
		System.setProperty("jcifs.netbios.cachePolicy", "0");
	}

	@Test
	public void testLookup() throws UnknownHostException
	{
		try
		{
			for (int i = 0; i < 10000; i++)
			{
				NbtAddress nbtAddress =
UniAddress.lookupServerOrWorkgroup("some-server-name-needed-resolved-via-dfs",
null);
				System.out.printf("%d-address=%s%n", i,
nbtAddress);
			}
		}
		catch(OutOfMemoryError e)
		{
			dumpThreads(e);
			throw e;
		}
	}

	private static void dumpThreads(Throwable e)
	{
		Map<Thread, StackTraceElement[]> allStackTraces =
Thread.getAllStackTraces();
		System.err.println("***Dumping threads on***");
		System.err.printf("%s%n", e);
		System.err.printf("Total number of threads=%d%n",
allStackTraces.size());
		for (Thread t : allStackTraces.keySet())
		{
			System.err.printf("%n%s-%s%n", t, t.getState());

			for (StackTraceElement se : allStackTraces.get(t))
			{
				System.err.printf("%s%n", se);
			}
		}
	}
}





More information about the jCIFS mailing list