【问题标题】:LdapTemplate search catch exception with parallel stream and LdapTemplateLdapTemplate 使用并行流和 LdapTemplate 搜索捕获异常
【发布时间】:2019-05-10 18:48:45
【问题描述】:

我有问题尝试使用带有并行性的 spring-ldap 搜索在 LDAP 上搜索组。

我正在进行批处理以将数据从 SQL 数据库加载到 LDAP。我使用 spring-boot 和 spring-ldap。

我的算法尝试使用其 gidNumber 在 ldap 搜索组。在没有并行性(stream.parallelStream)的情况下运行时效果很好。但是当我用 parallelStream 迭代一个列表时,我有时会遇到这个异常:

java.lang.ClassCastException: class com.sun.jndi.ldap.LdapCtx cannot be cast to class org.springframework.ldap.core.DirContextAdapter (com.sun.jndi.ldap.LdapCtx is in module java.naming of loader 'bootstrap'; org.springframework.ldap.core.DirContextAdapter is in unnamed module of loader java.net.URLClassLoader @4f0f76b4)

我已将对象从 ContextMapper#mapFromContext 转换为 DirContextAdapter。 Spring-ldap 参考说,如果我不更改 DirObjectFactory LdapContextSource,此方法应返回 DirContextAdapter 的实例。

我的代码类似于:

ldapTemplate.search(
query().base(groupName()).where("gidNumber").is(Long.toString(gid)),
            (ContextMapper<GroupLdap>) ctx -> {
                DirContextAdapter context = (DirContextAdapter) ctx;
                return new GroupLdap(context, true);
            })

我的应用程序是将数据从 SQL 数据库加载到 LDAP 的批处理。我使用 spring-boot 和 spring-ldap。

我正在使用 spring-boot 2.1.4、OpenLdap 和 ORACLE 到 SQL-DB。和 open-jdk-zulu 11.

我的算法尝试使用其 gidNumber 在 ldap 搜索组。在没有并行性(stream.parallelStream)的情况下运行时效果很好。但是,当我使用 parallelStream() 迭代列表时,有时会遇到 ClassCastException:

我设置了一个 ldap 池连接,但它不起作用。

我的代码类似于:

    ldapTemplate.search(
    query().base(groupName()).where("gidNumber").is(Long.toString(gid)),
                (ContextMapper<GroupLdap>) ctx -> {
                    DirContextAdapter context = (DirContextAdapter) ctx;
                    return new GroupLdap(context, true);
                })

groupName 是引用“ou=groups,dc=fff,dc=br”的名称;

gid 是一个带有 gitNumber 搜索组的数字。

GroupLdap 是 LDAP 上组的内部表示。

使用并行性,我有时会收到异常:

java.lang.ClassCastException: class com.sun.jndi.ldap.LdapCtx cannot be cast to class org.springframework.ldap.core.DirContextAdapter (com.sun.jndi.ldap.LdapCtx is in module java.naming of loader 'bootstrap'; org.springframework.ldap.core.DirContextAdapter is in unnamed module of loader java.net.URLClassLoader @4f0f76b4)

我已将对象从 ContextMapper#mapFromContext 转换为 DirContextAdapter。 Spring-ldap 参考说,如果我不更改 DirObjectFactory LdapContextSource,此方法应返回 DirContextAdapter 的实例。

【问题讨论】:

    标签: java spring-boot spring-ldap pooling


    【解决方案1】:

    我们与团队确认,将parallelStream()改为stream()解决了ClassCastException的问题。这绝对是一些 openJdk 缺陷。找不到任何相关内容:https://bugs.openjdk.java.net。一旦我重现孤立的问题,我会报告它。目前,parallelStream 并不总是有效(在少数设置上它可以在少数情况下运行)

    我使用并且可以使用parallelStream:

    Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T09:58:13+02:00) Maven 主页:C:\Program Files\apache-maven-3.5.2\bin.. Java 版本:11.0.5,供应商:甲骨文公司 Java 主页:C:\Program Files\Java\jdk-11.0.5 默认语言环境:en_US,平台编码:Cp1252 操作系统名称:“windows 10”,版本:“10.0”,arch:“amd64”,家族:“windows”

    同事遇到问题: 阿帕奇 Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-04T21:00:29+02:00) Maven 主页:C:\tools\ideaIU-2019.2.3.win\plugins\maven\lib\maven3 Java 版本:13.0.2,供应商:Oracle Corporation,运行时:C:\Program Files\Java\jdk-13.0.2 默认语言环境:en_US,平台编码:UTF-8 操作系统名称:“windows 10”,版本:“10.0”,arch:“amd64”,家族:“windows”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-30
      相关资源
      最近更新 更多