1、通过 run 命令启动 Jar 时设置
bin/flink run -Dexecution.runtime-mode=BATCH <jarFile>
2、在程序代码中通过执行环境设置
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
// env.setRuntimeMode(RuntimeExecutionMode.AUTOMATIC);
// env.setRuntimeMode(RuntimeExecutionMode.BATCH);
env.setRuntimeMode(RuntimeExecutionMode.STREAMING);
3、建议
在程序中不要写死,而是通过更灵活的方式进行选择。