Skip to content

Commit

Permalink
Fix executor for network requests (#648)
Browse files Browse the repository at this point in the history
  • Loading branch information
natario1 authored and rogerhu committed Apr 30, 2017
1 parent 803d260 commit 44eca49
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Parse/src/main/java/com/parse/ParseRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ private static ThreadPoolExecutor newThreadPoolExecutor(int corePoolSize, int ma
return executor;
}

/* package */ static final ExecutorService NETWORK_EXECUTOR = newThreadPoolExecutor(
/**
* This executor should be used for any network operation, in all subclasses.
* Chaining network operations with tasks consumed by Task.BACKGROUND_EXECUTOR , which is smaller,
* will cause performance bottlenecks and possibly lock the whole SDK.
*/
protected static final ExecutorService NETWORK_EXECUTOR = newThreadPoolExecutor(
CORE_POOL_SIZE, MAX_POOL_SIZE, KEEP_ALIVE_TIME, TimeUnit.SECONDS,
new LinkedBlockingQueue<Runnable>(MAX_QUEUE_SIZE), sThreadFactory);

Expand Down Expand Up @@ -147,7 +152,7 @@ public Task<Response> then(Task<Response> task) throws Exception {
}
return task;
}
}, Task.BACKGROUND_EXECUTOR);
}, NETWORK_EXECUTOR);
}

protected abstract Task<Response> onResponseAsync(ParseHttpResponse response,
Expand Down

0 comments on commit 44eca49

Please sign in to comment.