LDAP返回false时,NamingEnumeration hasMoreElements方法花费大量时间 [英] NamingEnumeration hasMoreElements method takes a lot of time when returning false for LDAP

查看:479
本文介绍了LDAP返回false时,NamingEnumeration hasMoreElements方法花费大量时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试搜索LDAP服务器(Active Directory).当我解析搜索结果时,NamingEnumerationhasMoreElements方法在返回false时需要花费大约15-20秒的时间来执行.返回true时情况并非如此.有办法解决这个问题吗?

I am trying to search a LDAP server(Active Directory). When I parse the search results, the hasMoreElements method of NamingEnumeration takes around 15-20 seconds to execute when it returns false. It is not the case when it is returning true. Is there a way to solve this issue?

代码:

SearchControls ctrl = new SearchControls();
ctrl.setSearchScope(SearchControls.SUBTREE_SCOPE);
String searchFilter = "(&(objectClass=user("uid"="abc"))";
NamingEnumeration ne = dirContext.search("ldap://abc:389/dc=abc,dc=xy", searchFilter,ctrl);

if (ne != null) {
    while (ne.hasMoreElements()) {
        //parse results
    }

推荐答案

上次调用hasMoreElements()时,NamingEnumeration进行了一些清理.它还检查是否存在其他引用,并且上下文属性Context.REFERRAL设置为"follow".在我们的软件中的一种情况下,这完全导致了所描述的行为:在LDAP上下文中搜索引荐时,对hasMoreElements()的最后一次调用(或对hasMore()next()的调用比允许的频繁得多)最多导致40秒.解决方案是不要将Context.REFERRAL设置为关注".

The NamingEnumeration does some cleanup when calling hasMoreElements() the last time. It also checks if there are additional referrals is the context-property Context.REFERRAL is set to "follow". In one case in our software this caused exactly the behaviour as described: The last call to hasMoreElements() (or to hasMore() or calling next() more often than allowed) caused up to 40 seconds as referrals are searched in the LDAP context. The solution is to not set Context.REFERRAL to "follow".

这篇关于LDAP返回false时,NamingEnumeration hasMoreElements方法花费大量时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆