1、概述
JobClient jobClient = StreamExecutionEnvironment.executeAsync();
jobClient.stopWithSavepoint(false,"/Users/*/Desktop/", SavepointFormatType.DEFAULT);
2、完整代码示例
import org.apache.flink.api.java.io.TextInputFormat;
import org.apache.flink.core.execution.JobClient;
import org.apache.flink.core.fs.Path;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.source.FileProcessingMode;
import org.apache.flink.util.CloseableIterator;
import java.io.File;
// 在 程序完成时 或者 CheckPoint触发时 才会输出结果
public class _04_JobClientStopWithSavepoint {
public static void main(String[] args) throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.enableCheckpointing(2000);
DataStreamSource<String> source = env.readFile(new TextInputFormat(Path.fromLocalFile(new File("word.txt")))
, "/Users/hhx/Desktop/word.txt"
, FileProcessingMode.PROCESS_CONTINUOUSLY
, 10000);
CloseableIterator<String> iterator = source.collectAsync();
JobClient jobClient = env.executeAsync();
// TimeUnit.SECONDS.sleep(5);
// jobClient.stopWithSavepoint(false,"/Users/*/Desktop/", SavepointFormatType.DEFAULT);
while (iterator.hasNext()){
System.out.println("iterator=>"+iterator.next());
}
}
}