Uploaded image for project: 'Flink'
  1. Flink
  2. FLINK-24558

dataStream can not use multiple classloaders

Agile BoardRank to TopRank to BottomAttach filesAttach ScreenshotBulk Copy AttachmentsBulk Move AttachmentsAdd voteVotersWatch issueWatchersCreate sub-taskConvert to sub-taskLinkCloneLabelsUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    Description

      create a dataStream demo as below,in the demo,create a very simple example,

      read stream data from sourceFunction,and send it to sinkFunction without any processing.
      The point is,by creating the instance of SourceFunction and SinkFunction has used two separately URLClassLoader with different dependencies,for avoiding the code conflict .

      but the problem is flink client send to server ,the server side throw an classNotFoundException which defined the de classloader dependencies, Obviously the server side has not use the classloader as client side.

      how can I solve the problem ,is there any one can give me some advice ? thanks a lot

      public class FlinkStreamDemo {
          public static void main(String[] args) throws Exception {
      
              StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
              SourceFunction<DTO> sourceFunc = createSourceFunction();
      
              DataStreamSource<DTO> dtoDataStreamSource = env.addSource(sourceFunc);
      
              SinkFunction<DTO> sinkFunction = createSink();
      
              dtoDataStreamSource.addSink(sinkFunction);
      
              env.execute("flink-example");
          }
      
          private static SinkFunction<DTO> createSink() {
              URL[] urls = new URL[]{...};
              ClassLoader classLoader = new URLClassLoader(urls);
              ServiceLoader<ISinkFunctionFactory> loaders = ServiceLoader.load(ISinkFunctionFactory.class, classLoader);
              Iterator<ISinkFunctionFactory> it = loaders.iterator();
              if (it.hasNext()) {
                  return it.next().create();
              }
              throw new IllegalStateException();
          }
      
          private static SourceFunction<DTO> createSourceFunction() {
              URL[] urls = new URL[]{...};
              ClassLoader classLoader = new URLClassLoader(urls);
              ServiceLoader<ISourceFunctionFactory> loaders = ServiceLoader.load(ISourceFunctionFactory.class, classLoader);
              Iterator<ISourceFunctionFactory> it = loaders.iterator();
              if (it.hasNext()) {
                  return it.next().create();
              }
              throw new IllegalStateException();
          }
      
          public interface ISinkFunctionFactory {
              SinkFunction<DTO> create();
          }
      
          public interface ISourceFunctionFactory {
              SourceFunction<DTO> create();
          }
      }
      

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            baisui bai sui
            baisui bai sui

            Dates

              Created:
              Updated:

              Slack

                Issue deployment