title: Spark Structured Streaming, multiples queries are not running concurrently
body: <p>I slightly modified example taken from here - <a href="https://github.com/apache/spark/blob/v2.2.0/examples/src/main/scala/org/apache/spark/examples/sql/streaming/StructuredNetworkWordCount.scala" rel="nofollow noreferrer">https://github.com/apache/spark/blob/v2.2.0/examples/src/main/scala/org/apache/spark/examples/sql/streaming/StructuredNetworkWordCount.scala</a></p>
  
  <p>I added seconds writeStream (sink):</p>
  
  <pre><code>scala
  case class MyWriter1() extends ForeachWriter[Row]{
    override def open(partitionId: Long, version: Long): Boolean = true
  
    override def process(value: Row): Unit = {
      println(s"custom1 - ${value.get(0)}")
    }
  
    override def close(errorOrNull: Throwable): Unit = true
  }
  
  case class MyWriter2() extends ForeachWriter[(String, Int)]{
    override def open(partitionId: Long, version: Long): Boolean = true
  
    override def process(value: (String, Int)): Unit = {
      println(s"custom2 - $value")
    }
  
    override def close(errorOrNull: Throwable): Unit = true
  }
  
  
  object Main extends Serializable{
  
    def main(args: Array[String]): Unit = {
      println("starting")
  
      Logger.getLogger("org").setLevel(Level.OFF)
      Logger.getLogger("akka").setLevel(Level.OFF)
  
      val host = "localhost"
      val port = "9999"
  
      val spark = SparkSession
        .builder
        .master("local[*]")
        .appName("app-test")
        .getOrCreate()
  
      import spark.implicits._
  
      // Create DataFrame representing the stream of input lines from connection to host:port
      val lines = spark.readStream
        .format("socket")
        .option("host", host)
        .option("port", port)
        .load()
  
      // Split the lines into words
      val words = lines.as[String].flatMap(_.split(" "))
  
      // Generate running word count
      val wordCounts = words.groupBy("value").count()
  
      // Start running the query that prints the running counts to the console
      val query1 = wordCounts.writeStream
        .outputMode("update")
        .foreach(MyWriter1())
        .start()
  
      val ds = wordCounts.map(x =&gt; (x.getAs[String]("value"), x.getAs[Int]("count")))
  
      val query2 = ds.writeStream
        .outputMode("update")
        .foreach(MyWriter2())
        .start()
  
      spark.streams.awaitAnyTermination()
  
    }
  }
  </code></pre>
  
  <p>Unfortunately, only first query runs, second never runs (MyWriter2 never been called)</p>
  
  <p>Please advice what I'm doing wrong. According to doc: You can start any number of queries in a single SparkSession. They will all be running concurrently sharing the cluster resources.</p>