Spark streaming output not saved to HDFS file

I am trying to save the Spark streaming output to a file on HDFS. Right now, it is not saving any file.

Here is my code :


SparkConf sparkConf = new SparkConf().setAppName("MyTestCOunt");
JavaStreamingContext ssc = new JavaStreamingContext(sparkConf,  new Duration(1000));

JavaReceiverInputDStream<String> lines = ssc.socketTextStream(args[0], Integer.parseInt(args[1]), StorageLevels.MEMORY_AND_DISK_SER);
JavaDStream<String> words = lines.flatMap(new FlatMapFunction<String, String>() {
                public Iterable<String> call(String x) {
                 return  Lists.newArrayList(SPACE.split(x));

JavaPairDStream<String, Integer> wordCounts = words.mapToPair(
      new PairFunction<String, String, Integer>() {
        public Tuple2<String, Integer> call(String s) {
                 return new Tuple2<String, Integer>(s, 1);
      }).reduceByKey(new Function2<Integer, Integer, Integer>() {
        public Integer call(Integer i1, Integer i2) {
          return i1 + i2;


wordCounts.print() works, but not wordCounts.saveAsHadoopFiles, any ideas why ?

I am running below commands :

1) nc -lk 9999

2) ./bin/run-example org.apache.spark.examples.streaming.NetworkWordCount localhost 9999

Thanks in advance..!!!


I fixed the same problem by specifying master as local[x] x > 1. If you run master as local, Spark could not assign slot to execute task. Like

SparkConf conf = new SparkConf().setAppName("conveyor").setMaster("local[4]");


wordCounts.dstream().saveAsTextFiles("hdfs://mynamenode:8020/user/spark/mystream/", "abc");



JavaDStream<String> lines; Initialize lines with our data.


lines.foreachRDD(new VoidFunction<JavaRDD<String>>() {
    public void call(JavaRDD<String > rdd) throws Exception {
    Date today = new Date();
    String date = (new SimpleDateFormat("dd-MM-yyyy").format(today));


I fixed this by changing the Sandbox / Server timezone to my local timezone, as my Twitter account has GMT and my Sandbox has UTC. I have used the following commands to change my Sandbox timezone:

chkconfig ntpd on
/etc/init.d/ntpd start

I haven't restarted my Hadoop services after the timezone change.

Need Your Help

Differences between decltype(void()) and decltype(void{})

c++ c++11 language-lawyer void decltype

This is a follow-up of the question: What does the void() in decltype(void()) mean exactly?.

Single ErrorDocument directive to catch all errors (.htaccess)

apache .htaccess mod-rewrite errordocument

Is there something like a wildcard directive to catch all possible errors and deal with them in a single custom error page?