1

I have a code implementation that uses LDAP functionality. Inorder to get values I am initially generating a InitialDirContext. I have set a timeout value of 2 seconds for establishing connection. But I can see that the thread waits for around 20 minutes for the context to generate. Below is the code:

Setting the timeouts -

env.put("com.sun.jndi.ldap.read.timeout", String.valueOf(2000));
env.put("com.sun.jndi.ldap.connect.timeout", String.valueOf(2000)); 

Method to create context -


DirContext getInitialDirContext(final Hashtable<String, Object> env) throws NamingException {
        final long timeinMillis = System.currentTimeMillis();
        try {
            return new InitialDirContext(env);
        } finally {
            LOGGER.info("Total time taken for creating the LDAP Initial Context in Millis [{}]",
                    System.currentTimeMillis() - timeinMillis);
        }
    }

Can anybody tell me why the timeout is not working. As a workaround I was thinking I'll stop the execution manually once time crosses the timeout limit. Does anyone have a better idea to handle this scenario.

Nit
  • 23
  • 6

0 Answers0