關閉Tomcat後,我們發現很多關於可能的內存泄漏的錯誤,因爲Tomcat未能停止線程。 根據Tomcat,我們在com.sun.jndi.ldap.Connection.pauseReader中有2600個daemon線程正在等待。使用LdapTemplate時LDAP連接未關閉
我們使用LdapTemplate從LDAP讀取數據。每次我們需要從LDAP讀取數據時都會創建LdapTemplate。從文檔中我看到所有的資源都是在搜索結束後由LdapTemplate發佈的。 我們尚未爲LdapTemplate啓用池,默認值爲false。
調試後,它看起來爲Connection創建的線程在搜索結束後不會立即銷燬,而是最終銷燬一些線程。
任何想法爲什麼我們會有這麼多守護線程等待com.sun.jndi.ldap.Connection.pauseReader?
我們使用的是spring-ldap 2.0.2.RELEASE。我們如何執行搜索之前創建LdapTemplate
示例代碼:
LdapContextSource contextSource = new LdapContextSource();
SimpleAuthenticationSource authenticationSource = new SimpleAuthenticationSource(userDn, password);
contextSource.setAuthenticationSource(authenticationSource);
LdapTemplate ldapTemplate = new LdapTemplate(contextSource);
ldapTemplate.setIgnorePartialResultException(true);
更新: 彙集設置爲true後的連接都被釋放確定。
ldapContextSource.setPooled(true);
問題是我們不能使用池。我仍然不明白爲什麼不使用連接池時連接沒有正確釋放。
你可以舉一個例子,你如何使用LdapTemplate,Spring版本和那種東西,它可以是有用的 – karelss