Github user seyfe commented on a diff in the pull request:

    https://github.com/apache/spark/pull/15371#discussion_r82468147
  
    --- Diff: core/src/main/scala/org/apache/spark/executor/TaskMetrics.scala 
---
    @@ -344,15 +338,20 @@ private[spark] class BlockStatusesAccumulator
       override def add(v: (BlockId, BlockStatus)): Unit = _seq.add(v)
     
       override def merge(
    -    other: AccumulatorV2[(BlockId, BlockStatus), java.util.List[(BlockId, 
BlockStatus)]]): Unit = {
    +    other: AccumulatorV2[(BlockId, BlockStatus), List[(BlockId, 
BlockStatus)]]): Unit = {
         other match {
    -      case o: BlockStatusesAccumulator => _seq.addAll(o.value)
    +      case o: BlockStatusesAccumulator => o.value.foreach(_seq.add)
           case _ => throw new UnsupportedOperationException(
             s"Cannot merge ${this.getClass.getName} with 
${other.getClass.getName}")
         }
       }
     
    -  override def value: java.util.List[(BlockId, BlockStatus)] = _seq
    +  // `asScala` accesses the internal values using `java.util.Iterator` so 
needs to be synchronized
    +  override def value: List[(BlockId, BlockStatus)] = {
    +    _seq.synchronized {
    --- End diff --
    
    Thanks for the review @zsxwing . I checked the java doc and it says that 
getting iterator is not thread safe and suggests below usage. That's why I did 
`_seq.synchronized`
    
    https://docs.oracle.com/javase/7/docs/api/java/util/Collections.html
    
    ```
      List list = Collections.synchronizedList(new ArrayList());
          ...
      synchronized (list) {
          Iterator i = list.iterator(); // Must be in synchronized block
          while (i.hasNext())
              foo(i.next());
      }
     
    ```
    
    Regarding your second questions, `JsonProtocal` is using it as Scala 
collection that is why I converted it to a Scala collection so we won't need to 
convert again.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to