在流启动之前访问Flink类加载器

Luk*_*ski 8 java scala apache-flink flink-streaming

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

然而,我正在进一步推进更多的问题,我不得不写(坏)代码,以避免这个问题.

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

这里的任何指导将不胜感激

yun*_*fan 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);
}
Run Code Online (Sandbox Code Playgroud)

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