Skip to content

Commit

Permalink
Actually allow applications to provide custom executors.
Browse files Browse the repository at this point in the history
When the interface was converted to an abstract class, we forgot to make the methods public.

Also add Javadoc to clarify the purpose of the provided queues. Apps may elect to provide shared executors while not making use of these queues for simplicity; this is fine as long as apps are not strongly dependent on the priority scheme. Note that ideally, most work is done on the non-blocking pool, and the priority is not relevant anyway.
  • Loading branch information
jpd236 committed Oct 13, 2020
1 parent ae701b3 commit 1c0ade3
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/main/java/com/android/volley/AsyncRequestQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -436,17 +436,24 @@ private void finishRequest(Request<?> mRequest, Response<?> response, boolean ca
}

/**
* This class may be used by advanced applications to provide custom executors according to
* their needs. Apps must create ExecutorServices dynamically given a blocking queue rather than
* providing them directly so that Volley can provide a PriorityQueue which will prioritize
* requests according to Request#getPriority.
* Factory to create/provide the executors which Volley will use.
*
* <p>This class may be used by advanced applications to provide custom executors according to
* their needs.
*
* <p>For applications which rely on setting request priority via {@link Request#getPriority}, a
* task queue is provided which will prioritize requests of higher priority should the thread
* pool itself be exhausted. If a shared pool is provided which does not make use of the given
* queue, then lower-priority requests may have tasks executed before higher-priority requests
* when enough tasks are in flight to fully saturate the shared pool.
*/
public abstract static class ExecutorFactory {
abstract ExecutorService createNonBlockingExecutor(BlockingQueue<Runnable> taskQueue);
public abstract ExecutorService createNonBlockingExecutor(
BlockingQueue<Runnable> taskQueue);

abstract ExecutorService createBlockingExecutor(BlockingQueue<Runnable> taskQueue);
public abstract ExecutorService createBlockingExecutor(BlockingQueue<Runnable> taskQueue);

abstract ScheduledExecutorService createNonBlockingScheduledExecutor();
public abstract ScheduledExecutorService createNonBlockingScheduledExecutor();
}

/** Provides a BlockingQueue to be used to create executors. */
Expand Down

0 comments on commit 1c0ade3

Please sign in to comment.