Skip to content

Commit

Permalink
[SPARK-12701][CORE] FileAppender should use join to ensure writing th…
Browse files Browse the repository at this point in the history
…read completion

Changed Logging FileAppender to use join in `awaitTermination` to ensure that thread is properly finished before returning.

Author: Bryan Cutler <[email protected]>

Closes apache#10654 from BryanCutler/fileAppender-join-thread-SPARK-12701.
  • Loading branch information
BryanCutler authored and zsxwing committed Jan 8, 2016
1 parent cfe1ba5 commit ea104b8
Showing 1 changed file with 1 addition and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ private[spark] class FileAppender(inputStream: InputStream, file: File, bufferSi
extends Logging {
@volatile private var outputStream: FileOutputStream = null
@volatile private var markedForStop = false // has the appender been asked to stopped
@volatile private var stopped = false // has the appender stopped

// Thread that reads the input stream and writes to file
private val writingThread = new Thread("File appending thread for " + file) {
Expand All @@ -47,11 +46,7 @@ private[spark] class FileAppender(inputStream: InputStream, file: File, bufferSi
* or because of any error in appending
*/
def awaitTermination() {
synchronized {
if (!stopped) {
wait()
}
}
writingThread.join()
}

/** Stop the appender */
Expand All @@ -77,10 +72,6 @@ private[spark] class FileAppender(inputStream: InputStream, file: File, bufferSi
logError(s"Error writing stream to file $file", e)
} finally {
closeFile()
synchronized {
stopped = true
notifyAll()
}
}
}

Expand Down

0 comments on commit ea104b8

Please sign in to comment.