【问题标题】:Accessing Flink Classloader before Stream Start在 Stream Start 之前访问 Flink Classloader
【发布时间】:2018-08-08 16:01:12
【问题描述】:

在我的项目中,我想在流执行之前访问 Flink 用户类加载器。在流执行之前,我一直在实例化我自己的类加载器以反序列化类(尽我所能避免与多个类加载器相关的问题)。

但是,我越是进步,就越需要编写(错误的)代码来避免这个问题。

如果我可以访问 Flink 用户类加载器并使用它,这可以解决,但是我在“RichFunctions”之外没有看到这样做的机制 (https://ci.apache.org/projects/flink/flink-docs-stable/api/java/org/apache/flink/api/common/functions/RichFunction.html) 需要流运行。

如有任何指导,我们将不胜感激

【问题讨论】:

  • 你想在哪里访问用户类加载器?在 main 方法中,在您的用户定义函数中?

标签: java scala apache-flink flink-streaming


【解决方案1】:

你可以在 flink 中使用自己的类加载器。

自己构建图表并与客户端一起提交类加载器。

代码如下:

final StandaloneClusterClient client;
try {
    client = new StandaloneClusterClient(configuration);
} catch (final Exception e) {
    throw new RuntimeException("Could not establish a connection to the job manager", e);
}

try {
    ClassLoader classLoader = JobWithJars.buildUserCodeClassLoader(
            Collections.<URL>singletonList(uploadedJarUrl),
            Collections.<URL>emptyList(),
            this.getClass().getClassLoader());
    client.runDetached(jobGraph, classLoader);
} catch (final ProgramInvocationException e) {
    throw new RuntimeException("Cannot execute job due to ProgramInvocationException", e);
}

但我还是想知道你为什么要自己的类加载器,它可能可以通过其他方式实现。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-21
    • 2018-08-17
    • 1970-01-01
    • 2017-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多