Java代理中使用JNDI出现“ Error cleaning up threads”问题

我们在Java代理中通过JNDI查询LDAP数据的时候,出现 “ Error cleaning up threads” 错误信息。虽然代理返回的结果正确,但是有人提出可能会导致内存泄漏。最后查明只要在close LdapContext 对象之前,将 NamingEnumeration 对象也 close 就可以了。部分代码如下:

LdapContext ctx = LDAPLogin(“cn=xxxxx, ou=xx, ou=xx, o=xxxx”, “password”, “ldap://ldap.mycompany.com:389”);
……
NamingEnumeration ne = ctx.search(“”,”(&(objectclass=person)(cn=” + doc.getItemValueString(“Mod_Remote_User”) + “))”, constraints);
……
ne.close();
ctx.close();

这样我就安心了。