JNDI Connection Pool issue

N

nathaniel_auvil

I have found something strange with the jdk jndi connection pool. The
pool will lock if you do not iterate all the data returned from a
query. I attached code i was using to test.

If you do not iterate over all the results returned by the query, the
pool will lock until the timeout is reached. Try commenting out the
SearchResults and running.



public class JDKConnectionPool implements Runnable
{
private static HashMap connections;

private static long sleepMillis= 1000;
private static int numThreads= 25;
private static int activeThreads= numThreads;
private int numQueries= 3;


/************************************************************************************************
*
* @param args[]

***********************************************************************************************/
public static void main( String[] args )
{
System.setProperty( "com.sun.jndi.ldap.connect.pool.debug", "all" );
System.setProperty( "com.sun.jndi.ldap.connect.pool.maxsize", "3" );
System.setProperty( "com.sun.jndi.ldap.connect.pool.initsize", "3" );
System.setProperty( "com.sun.jndi.ldap.connect.pool.prefsize", "3" );
System.setProperty( "com.sun.jndi.ldap.connect.pool.timeout", "30000"
);

connections= new HashMap();

for( int i= 0; i < numThreads; i++ )
{
JDKConnectionPool poolTester= new JDKConnectionPool();
Thread thread= new Thread( poolTester, "" + i );
thread.start();
}
}


/************************************************************************************************
*

***********************************************************************************************/
public void run()
{
Hashtable ht= new Hashtable();
ht.put( Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory" );
ht.put( "com.sun.jndi.ldap.connect.pool", "true" );
ht.put( Context.PROVIDER_URL,
"ldap://myldap.mycompany.com:389/o=theRoot" );

InitialDirContext ctx= null;

while( this.numQueries > 0 )
{
try
{
ctx= new InitialDirContext( ht );
Attributes matchAttributes= new BasicAttributes();

//displayResults( ctx.search( "ou=somePeople", matchAttributes ) );

NamingEnumeration namingEnumeration= ctx.search( "ou=somePeople",
matchAttributes );
while( namingEnumeration.hasMoreElements() )
{

SearchResult searchResult= (SearchResult)
namingEnumeration.next();
//System.out.println( "found: " + searchResult.getName() );
break;
}
}
catch( Exception e )
{
e.printStackTrace();
}
finally
{
try
{
if( ctx != null )
{
ctx.close();
Thread.yield();
}
}
catch( Exception e )
{
e.printStackTrace();
}
}

this.numQueries--;
}

activeThreads--;
System.out.println( "----Thread: " + Thread.currentThread().getName()
+ " is done!!!!!!!" );

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top