Skip to content

Commit

Permalink
Use CAS when terminating thread
Browse files Browse the repository at this point in the history
  • Loading branch information
xerial committed Sep 1, 2016
1 parent 62f3ea0 commit fdbaf36
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions wvlet-log/src/main/scala/wvlet/log/LogLevelScanner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ private[log] class LogLevelScanner extends Guard {
private var lastScannedMillis: Option[Long] = None

private def run {
while (state.get() != STOPPING) {
// We need to exit here so that the thread can be automatically discarded after the scan interval has passed
// Otherwise, the thread remains in the classloader(s) if used for running test cases
while (!state.compareAndSet(STOPPING, STOPPED)) {
// Periodically run
val currentTimeMillis = System.currentTimeMillis()
val scanIntervalMillis = getConfig.scanInterval.toMillis
Expand All @@ -145,10 +147,6 @@ private[log] class LogLevelScanner extends Guard {
}
}
}

// We need to exit here so that the thread can be automatically discarded after the scan interval has passed
// Otherwise, the thread remains in the classloader(s) if used for running test cases
state.set(STOPPED)
}

private class LogLevelScannerThread extends Thread {
Expand Down

0 comments on commit fdbaf36

Please sign in to comment.