Skip to content

Commit

Permalink
Work for the issue google#60.
Browse files Browse the repository at this point in the history
  • Loading branch information
xyhuangjinfu committed Aug 2, 2017
1 parent d40b75f commit c6ea7c0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
10 changes: 2 additions & 8 deletions src/main/java/com/android/volley/CacheDispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ public class CacheDispatcher extends Thread {
/** For posting responses. */
private final ResponseDelivery mDelivery;

/** Used for telling us to die. */
private volatile boolean mQuit = false;

/**
* Creates a new cache triage dispatcher thread. You must call {@link #start()}
* in order to begin processing.
Expand All @@ -71,7 +68,6 @@ public CacheDispatcher(
* the queue, they are not guaranteed to be processed.
*/
public void quit() {
mQuit = true;
interrupt();
}

Expand All @@ -83,7 +79,7 @@ public void run() {
// Make a blocking call to initialize the cache.
mCache.initialize();

while (true) {
while (!isInterrupted()) {
try {
// Get a request from the cache triage queue, blocking until
// at least one is available.
Expand Down Expand Up @@ -148,9 +144,7 @@ public void run() {

} catch (InterruptedException e) {
// We may have been interrupted because it was time to quit.
if (mQuit) {
return;
}
return;
}
}
}
Expand Down
10 changes: 2 additions & 8 deletions src/main/java/com/android/volley/NetworkDispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ public class NetworkDispatcher extends Thread {
private final Cache mCache;
/** For posting responses and errors. */
private final ResponseDelivery mDelivery;
/** Used for telling us to die. */
private volatile boolean mQuit = false;

/**
* Creates a new network dispatcher thread. You must call {@link #start()}
Expand All @@ -67,7 +65,6 @@ public NetworkDispatcher(BlockingQueue<Request<?>> queue,
* the queue, they are not guaranteed to be processed.
*/
public void quit() {
mQuit = true;
interrupt();
}

Expand All @@ -82,18 +79,15 @@ private void addTrafficStatsTag(Request<?> request) {
@Override
public void run() {
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
while (true) {
while (!isInterrupted()) {
long startTimeMs = SystemClock.elapsedRealtime();
Request<?> request;
try {
// Take a request from the queue.
request = mQueue.take();
} catch (InterruptedException e) {
// We may have been interrupted because it was time to quit.
if (mQuit) {
return;
}
continue;
return;
}

try {
Expand Down

0 comments on commit c6ea7c0

Please sign in to comment.