title: Spark Accumulator value not read by task
body: <p>I am initializing an accumulator </p>
  
  <p><code>final Accumulator&lt;Integer&gt; accum = sc.accumulator(0);</code></p>
  
  <p>And then while in map function , I'm trying to increment the accumulator , then using the accumulator value in setting a variable.</p>
  
  <pre><code>JavaRDD&lt;UserSetGet&gt; UserProfileRDD1 = temp.map(new Function&lt;String, UserSetGet&gt;() {
  
              @Override
              public UserSetGet call(String arg0) throws Exception {
  
                      UserSetGet usg = new UserSetGet();
  
                      accum.add(1);
                      usg.setPid(accum.value().toString();
  
  
              }
    });
  </code></pre>
  
  <p>But Im getting the following error.</p>
  
  <blockquote>
    <p>16/03/14 09:12:58 ERROR executor.Executor: Exception in task 0.0 in
    stage 2.0 (TID 2) java.lang.UnsupportedOperationException: Can't read
    accumulator value in task</p>
  </blockquote>
  
  <p>EDITED - As per the answer from Avihoo Mamka, getting accumulator value in tasks is not possible.</p>
  
  <p>So is there anyway I can achieve the same in parallel. Such that the Pid value gets set each time a variable(eg like static variable) is incremented in my map function.</p>