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!!!!!!!" );
}
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!!!!!!!" );
}