Skip to content

Commit

Permalink
Re-raise swallowed interrupts and log warnings for spurious (#195)
Browse files Browse the repository at this point in the history
interrupts.

Volley relies on a quit() method and mQuit flag on both dispatcher
threads to shut down those threads. These could just use the interrupt
state instead, but as noted on #60, these are public, non-final
classes, and so relying on interrupt depends on external callers and
subclasses using the interrupt state correctly.

To be more conservative and retain existing behavior, we keep the quit
method/flag around to ensure that we only shut down the dispatchers
when quit() is called. However, we re-raise the interrupt flag in this
case. If we're interrupted outside of quit(), we suppress the
interrupt flag and log a warning instead.

Fixes #60
  • Loading branch information
jpd236 authored May 30, 2018
1 parent 608f982 commit 0c32d6a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/android/volley/CacheDispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ public void run() {
} catch (InterruptedException e) {
// We may have been interrupted because it was time to quit.
if (mQuit) {
Thread.currentThread().interrupt();
return;
}
VolleyLog.e(
"Ignoring spurious interrupt of CacheDispatcher thread; "
+ "use quit() to terminate it");
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/android/volley/NetworkDispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ public void run() {
} catch (InterruptedException e) {
// We may have been interrupted because it was time to quit.
if (mQuit) {
Thread.currentThread().interrupt();
return;
}
VolleyLog.e(
"Ignoring spurious interrupt of NetworkDispatcher thread; "
+ "use quit() to terminate it");
}
}
}
Expand Down

0 comments on commit 0c32d6a

Please sign in to comment.