title: How Spark tasks in the same executor share variables (NumberFormatException with SimpleDateFormat)?
body: <p>The spark docs says that </p>
  
  <blockquote>
    <p>By default, when Spark runs a function in parallel as a set of tasks on different nodes, it ships a copy of each variable used in the function to each task.</p>
  </blockquote>
  
  <p>If I create a Java <code>SimpleDateFormat</code> and use it in RDD operations, I got a exception <code>NumberFormatException: multiple points</code>. </p>
  
  <p>I know <code>SimpleDateFormat</code> is not thread-safe. But as said by spark docs, this <code>SimpleDateFormat</code> object is copied to each task, so there should not be multiple threads accessing this object.</p>
  
  <p>I speculate that all task in one executor shares the same <code>SimpleDateFormate</code> object, am I right?</p>
  
  <hr>
  
  <p>This program prints the same object <code>java.text.SimpleDateFormat@f82ede60</code></p>
  
  <pre><code>object NormalVariable {
  
    // create dateFormat here doesn't change
    // val dateFormat = new SimpleDateFormat("yyyy.MM.dd")
  
    def main(args: Array[String]) {
  
      val dateFormat = new SimpleDateFormat("yyyy.MM.dd")
  
      val conf = new SparkConf().setAppName("Spark Test").setMaster("local[*]")
      val spark = new SparkContext(conf)
  
      val dates = Array[String]("1999.09.09", "2000.09.09", "2001.09.09", "2002.09.09", "2003.09.09")
  
      println(dateFormat)
  
      val resultes = spark.parallelize(dates).map { i =&gt;
        println(dateFormat)
        dateFormat.parse(i)
      }.collect()
  
      println(resultes.mkString(" "))
      spark.stop()
    }
  }
  </code></pre>