Skip to content

Commit ea104b8

Browse files
BryanCutlerzsxwing
authored andcommitted
[SPARK-12701][CORE] FileAppender should use join to ensure writing thread completion
Changed Logging FileAppender to use join in `awaitTermination` to ensure that thread is properly finished before returning. Author: Bryan Cutler <[email protected]> Closes #10654 from BryanCutler/fileAppender-join-thread-SPARK-12701.
1 parent cfe1ba5 commit ea104b8

File tree

1 file changed

+1
-10
lines changed

1 file changed

+1
-10
lines changed

core/src/main/scala/org/apache/spark/util/logging/FileAppender.scala

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ private[spark] class FileAppender(inputStream: InputStream, file: File, bufferSi
2929
extends Logging {
3030
@volatile private var outputStream: FileOutputStream = null
3131
@volatile private var markedForStop = false // has the appender been asked to stopped
32-
@volatile private var stopped = false // has the appender stopped
3332

3433
// Thread that reads the input stream and writes to file
3534
private val writingThread = new Thread("File appending thread for " + file) {
@@ -47,11 +46,7 @@ private[spark] class FileAppender(inputStream: InputStream, file: File, bufferSi
4746
* or because of any error in appending
4847
*/
4948
def awaitTermination() {
50-
synchronized {
51-
if (!stopped) {
52-
wait()
53-
}
54-
}
49+
writingThread.join()
5550
}
5651

5752
/** Stop the appender */
@@ -77,10 +72,6 @@ private[spark] class FileAppender(inputStream: InputStream, file: File, bufferSi
7772
logError(s"Error writing stream to file $file", e)
7873
} finally {
7974
closeFile()
80-
synchronized {
81-
stopped = true
82-
notifyAll()
83-
}
8475
}
8576
}
8677

0 commit comments

Comments
 (0)