问题描述
我运行spark自带的Wordcount例子,为什么只有在CTRL+C后,才会在命令行输出结果?即使把print()改成saveastextfile,也是在中断程序后才写文件。请教各位这是什么原因?代码如下:objectKafkaWordCount{defmain(args:Array[String]){if(args.length<4){System.err.println("Usage:KafkaWordCount<zkQuorum><group><topics><numThreads>")System.exit(1)}StreamingExamples.setStreamingLogLevels()valArray(zkQuorum,group,topics,numThreads)=argsvalsparkConf=newSparkConf().setAppName("KafkaWordCount")valssc=newStreamingContext(sparkConf,Seconds(2))ssc.checkpoint("checkpoint")valtopicMap=topics.split(",").map((_,numThreads.toInt)).toMapvallines=KafkaUtils.createStream(ssc,zkQuorum,group,topicMap).map(_._2)valwords=lines.flatMap(_.split(""))valwordCounts=words.map(x=>(x,1L)).reduceByKeyAndWindow(_+_,_-_,Minutes(10),Seconds(2),2)wordCounts.print()ssc.start()ssc.awaitTermination()}}