小编Sud*_*r S的帖子

在LDAP中实现超时

我一直在处理我们使用LDAP获取用户详细信息的应用程序.有时需要更多时间来获取用户详细信息.我想在获取详细信息的方法上实现超时,以便在最坏的情况下我们可以避免在服务器中挂起事务.

这里我们使用LdapUtil的是已配置LdapTemplate类的类来获取所需的详细信息.

我们如何在LDAP方法上实现超时? (在这种情况下的ldapTemplate.search(...)方法)

public class LdapUtil {

    @Autowired(required = true)
    @Qualifier(value = "ldapTemplateApp")
    LdapTemplate ldapTemplate;

    public Set < ProductGroup > findProducts(String UserId) {
        final Set < ProductGroup > products = newHashSet();
        // Lookup the user         
        String usrFilter = String.format(USERID_FILTER, globalUserId);

        ldapTemplate.search("ou=Members", usrFilter, // note this line
        new NameClassPairCallbackHandler() {

            public void handleNameClassPair(NameClassPair nameClassPair) {
                SearchResult result = (SearchResult) nameClassPair;
                String user = result.getNameInNamespace();

                String GrpFilter = String.format(GROUP_FILTER, user);

                List …
Run Code Online (Sandbox Code Playgroud)

java spring ldap ldapconnection spring-ldap

2
推荐指数
1
解决办法
5321
查看次数

在HASHMAP中计算密钥的哈希码两次

我一直在研究Hashmap实现的内部.

为了根据密钥从map添加或获取值,它将计算哈希码,然后它找到桶位置(或表位置/索引,如果我错了,请纠正我).
但它正在计算两次哈希码.

在下面的代码片段中,key.hashcode()是对象类中的本机方法,然后哈希方法在同一个类中实现.
它在哈希方法的注释中给出了为什么它被计算两次,这是我无法理解的.

任何人都可以用一个场景简要解释一下吗?

int hash = hash(key.hashCode());

/ * Applies a supplemental hash function to a given hashCode, which
* defends against poor quality hash functions.  This is critical
* because HashMap uses power-of-two length hash tables, that
* otherwise encounter collisions for hashCodes that do not differ
* in lower bits. Note: Null keys always map to hash 0, thus index 0.           
*/
static int hash(int h) {
    // This function ensures that hashCodes …
Run Code Online (Sandbox Code Playgroud)

java

0
推荐指数
1
解决办法
1423
查看次数

标签 统计

java ×2

ldap ×1

ldapconnection ×1

spring ×1

spring-ldap ×1