Skip to content

Commit be42bcf

Browse files
committed
Update as per review suggestion
1 parent e06bd4f commit be42bcf

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

streaming/src/main/scala/org/apache/spark/streaming/ContextWaiter.scala

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,18 @@
1717

1818
package org.apache.spark.streaming
1919

20-
import java.util.concurrent.{TimeoutException, TimeUnit}
20+
import java.util.concurrent.TimeUnit
2121
import java.util.concurrent.locks.ReentrantLock
22-
import javax.annotation.concurrent.GuardedBy
2322

2423
private[streaming] class ContextWaiter {
2524

2625
private val lock = new ReentrantLock()
2726
private val condition = lock.newCondition()
2827

29-
@GuardedBy("lock")
28+
// Guarded by "lock"
3029
private var error: Throwable = null
3130

32-
@GuardedBy("lock")
31+
// Guarded by "lock"
3332
private var stopped: Boolean = false
3433

3534
def notifyError(e: Throwable) = {
@@ -60,29 +59,19 @@ private[streaming] class ContextWaiter {
6059
lock.lock()
6160
try {
6261
if (timeout < 0) {
63-
while (true) {
64-
// If already stopped, then exit
65-
if (stopped) return true
66-
// If already had error, then throw it
67-
if (error != null) throw error
68-
62+
while (!stopped && error == null) {
6963
condition.await()
7064
}
7165
} else {
7266
var nanos = TimeUnit.MILLISECONDS.toNanos(timeout)
73-
while (true) {
74-
// If already stopped, then exit
75-
if (stopped) return true
76-
// If already had error, then throw it
77-
if (error != null) throw error
78-
// If no time remains, then exit
79-
if (nanos <= 0) return false
80-
67+
while (!stopped && error == null && nanos > 0) {
8168
nanos = condition.awaitNanos(nanos)
8269
}
8370
}
84-
// Never reached. Make the compiler happy.
85-
true
71+
// If already had error, then throw it
72+
if (error != null) throw error
73+
// already stopped or timeout
74+
stopped
8675
} finally {
8776
lock.unlock()
8877
}

0 commit comments

Comments
 (0)