老师我有个source并行度问题想请教您一下:
来源:2-4 基于官方提供的命令来构建Flink项目

qq_笑靥如她_0
2021-12-21
public class sourceMain {
public static void main(String[] args) throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.setParallelism(2);
test01(env);
//test02(env);
//test03(env);
//test04(env);
env.execute();
}
/**
*测试SourceFunction
*/
public static void test01(StreamExecutionEnvironment env){
DataStreamSource<Student> studentDataStreamSource = env.addSource(new TestSourceFun());
studentDataStreamSource.print();
//env.setParallelism(2);
System.out.println("全局并行度为:"+env.getParallelism());
System.out.println("当前SourceFunction的并行度为:"+studentDataStreamSource.getParallelism());//打印当前SourceFunction的并行度
}
如上代码,我在main函数里设置了全局并行度为2,控制台就正常输出2个线程。
但如果我在test01方法里设置全局的并行度为2,控制台打印的并行度还是2,但是有四个线程输出了结果。我有点不太明白就是这里不应该也是2个线程输出吗?
写回答
1回答
-
Michael_PK
2021-12-22
你的这个TestSourceFun的并行度是多少?
你可以贴出你的完整的代码,我可以直接贴到我idea中运行的,我到本地试试看。
我怀疑你的本地的core是4
然后代码哪里不对导致4个线程了,
你贴代码,注释的不要的不要贴,只要完整的需要的代码
032021-12-29
相似问题