Skip to content

Commit 09ae762

Browse files
author
Brandon Krieger
committed
code review
1 parent f212da3 commit 09ae762

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

core/src/main/scala/org/apache/spark/broadcast/TorrentBroadcast.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package org.apache.spark.broadcast
1919

2020
import java.io._
21-
import java.lang.ref.WeakReference
21+
import java.lang.ref.SoftReference
2222
import java.nio.ByteBuffer
2323
import java.util.zip.Adler32
2424

@@ -63,10 +63,10 @@ private[spark] class TorrentBroadcast[T: ClassTag](obj: T, id: Long)
6363
* which builds this value by reading blocks from the driver and/or other executors.
6464
*
6565
* On the driver, if the value is required, it is read lazily from the block manager. We hold
66-
* a weak reference so that it can be garbage collected if required, as we can always reconstruct
66+
* a soft reference so that it can be garbage collected if required, as we can always reconstruct
6767
* in the future.
6868
*/
69-
@transient private var _value: WeakReference[T] = _
69+
@transient private var _value: SoftReference[T] = _
7070

7171
/** The compression codec to use, or None if compression is disabled */
7272
@transient private var compressionCodec: Option[CompressionCodec] = _
@@ -95,13 +95,13 @@ private[spark] class TorrentBroadcast[T: ClassTag](obj: T, id: Long)
9595
/** The checksum for all the blocks. */
9696
private var checksums: Array[Int] = _
9797

98-
override protected def getValue() = {
98+
override protected def getValue() = synchronized {
9999
val memoized: T = if (_value == null) null.asInstanceOf[T] else _value.get
100100
if (memoized != null) {
101101
memoized
102102
} else {
103103
val newlyRead = readBroadcastBlock()
104-
_value = new WeakReference[T](newlyRead)
104+
_value = new SoftReference[T](newlyRead)
105105
newlyRead
106106
}
107107
}

0 commit comments

Comments
 (0)