2014-11-21 67 views
2

我在我的項目中實現了LDAP連接池,並注意到一個奇怪的行爲,每當新的連接請求到來時,我配置的LDAP連接池都將返回新連接,而不是重新使用現有連接返回到池。每次從Ldap連接池返回新連接

LDAP JNDI日誌

00:07:10,824 ERROR [stderr] (IPAdminGlobalDataReloader) Create and use [email protected][eun2p3-be.stp-qa.st.com:636] 
00:07:12,222 ERROR [stderr] (IPAdminGlobalDataReloader) Release [email protected] 
00:07:46,704 ERROR [stderr] (Thread-65) Expired [email protected] expired 
00:08:46,707 ERROR [stderr] (Thread-65) Expired [email protected] expired 
00:22:26,329 ERROR [stderr] (IPAdminGlobalDataReloader) Create [email protected][eun2p3-be.stp-qa.st.com:636] 
00:22:26,333 ERROR [stderr] (IPAdminGlobalDataReloader) Create and use [email protected][eun2p3-be.stp-qa.st.com:636] 
00:22:27,748 ERROR [stderr] (IPAdminGlobalDataReloader) Release [email protected] 
00:22:46,730 ERROR [stderr] (Thread-65) Expired [email protected] expired 
00:23:46,734 ERROR [stderr] (Thread-65) Expired [email protected] expired 
00:37:45,242 ERROR [stderr] (IPAdminGlobalDataReloader) Create [email protected][eun2p3-be.stp-qa.st.com:636] 
00:37:45,244 ERROR [stderr] (IPAdminGlobalDataReloader) Create and use [email protected][eun2p3-be.stp-qa.st.com:636] 
00:37:46,759 ERROR [stderr] (Thread-65) Expired [email protected] expired 
00:37:46,823 ERROR [stderr] (IPAdminGlobalDataReloader) Release [email protected] 
00:39:46,764 ERROR [stderr] (Thread-65) Expired [email protected] expired 
00:53:00,864 ERROR [stderr] (IPAdminGlobalDataReloader) Create [email protected][eun2p3-be.stp-qa.st.com:636] 
00:53:00,865 ERROR [stderr] (IPAdminGlobalDataReloader) Create and use [email protected][eun2p3-be.stp-qa.st.com:636] 
00:53:02,392 ERROR [stderr] (IPAdminGlobalDataReloader) Release [email protected] 
00:53:46,787 ERROR [stderr] (Thread-65) Expired [email protected] expired 
00:54:46,791 ERROR [stderr] (Thread-65) Expired [email protected] expired 

我的連接設置:在確定

Hashtable<String, String> env = new Hashtable<String, String>(); 

    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); 
    env.put(Context.PROVIDER_URL, "ldaps://" + server + ":" + serverPort); 
    env.put(Context.SECURITY_AUTHENTICATION, "simple"); 
    env.put(Context.SECURITY_PRINCIPAL, pUserName); 
    env.put(Context.SECURITY_CREDENTIALS, pPassword); 
    env.put(LdapContext.CONTROL_FACTORIES, "com.sun.jndi.ldap.ControlFactory"); 
    env.put(Context.SECURITY_PROTOCOL, "ssl"); 
    env.put("com.sun.jndi.ldap.read.timeout", "300000"); 

    Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); 

    // load the location of keystore that holds trusted root certificates from web.xml 
    ServletContext context = ApplicationServlet.getApplication().getServlet().getServletContext(); 
    String certificatePath = context.getInitParameter("AD_CERTIFICATE_PATH"); 

    System.setProperty("javax.net.ssl.trustStore", certificatePath); 
    //   System.setProperty("javax.net.debug", "all"); 

    // For connection pooling 
    env.put("com.sun.jndi.ldap.connect.pool", "true"); 
    System.setProperty("com.sun.jndi.ldap.connect.pool.protocol", "plain ssl"); 
    System.setProperty("com.sun.jndi.ldap.connect.pool.maxsize", poolMaxSize); 
    System.setProperty("com.sun.jndi.ldap.connect.pool.prefsize", poolPrefSize); 
    System.setProperty("com.sun.jndi.ldap.connect.pool.timeout", poolTimeOut); 
    System.setProperty("com.sun.jndi.ldap.connect.pool.debug", "fine"); 

    ctx = new InitialDirContext(env); 
    return (DirContext) ctx; 

由於這裏是根本原因,爲什麼每次新的連接被創建,而不是重複使用。

+0

顯然您的游泳池超時已到期。注意你不需要添加SSL提供商十年。 – EJP 2014-11-21 09:28:33

+0

Connection Timeout設置爲5分鐘,並且每個日誌連接立即過期。 – 2014-11-21 09:37:47

+0

由於超時屬性設置爲5分鐘,理想情況下,空閒連接應在到期前等待5分鐘。 – 2014-11-21 09:39:20

回答

-2

您尚未實施任何連接池,您正在使用來自Sun的中斷DirContext連接池。這是不鼓勵的。看看Spring LDAP的ContextSource池。它工作得很好。

+0

下定決心。他或者正在使用SuN連接池,或者他沒有使用任何連接池。 Sun JNDI連接池適用於我, – EJP 2014-11-21 09:50:09

+0

我們正在使用Sun JNDI連接池... – 2014-11-21 12:43:40

+0

而且'這被勸阻'了誰? – EJP 2014-11-21 23:33:54