@@ -21,8 +21,9 @@ import java.io._
21
21
import java .net .URI
22
22
import java .nio .charset .StandardCharsets
23
23
import java .util .Locale
24
+ import java .util .concurrent .ConcurrentHashMap
25
+ import java .util .function .Function
24
26
25
- import scala .collection .mutable
26
27
import scala .collection .mutable .ArrayBuffer
27
28
28
29
import org .apache .hadoop .conf .Configuration
@@ -290,7 +291,7 @@ private[spark] object EventLoggingListener extends Logging {
290
291
private val LOG_FILE_PERMISSIONS = new FsPermission (Integer .parseInt(" 770" , 8 ).toShort)
291
292
292
293
// A cache for compression codecs to avoid creating the same codec many times
293
- private val codecMap = new mutable. HashMap [String , CompressionCodec ]
294
+ private val codecMap = new ConcurrentHashMap [String , CompressionCodec ]
294
295
295
296
/**
296
297
* Write metadata about an event log to the given stream.
@@ -357,7 +358,10 @@ private[spark] object EventLoggingListener extends Logging {
357
358
val in = new BufferedInputStream (fs.open(log))
358
359
try {
359
360
val codec = codecName(log).map { c =>
360
- codecMap.getOrElseUpdate(c, CompressionCodec .createCodec(new SparkConf , c))
361
+ codecMap.computeIfAbsent(c, new Function [String , CompressionCodec ] {
362
+ override def apply (key : String ): CompressionCodec =
363
+ CompressionCodec .createCodec(new SparkConf , key)
364
+ })
361
365
}
362
366
codec.map(_.compressedInputStream(in)).getOrElse(in)
363
367
} catch {
0 commit comments