Parallel Work
Suppose you have N pieces of work to be done in (approximate) parallel. As it turns out, enqueue() on WorkManager takes either a varargs of WorkRequest or a List of WorkRequest objects. If you pass in more than one WorkRequest, all will be enqueued, and all will run when possible, based upon their constraints and the number of threads in the WorkManager thread pool.
WorkManager has a default thread pool, and in many cases it will be sufficient for your needs. If you wish to control that thread pool, call the static initialize() on WorkManager once, such as from onCreate() of a custom Application. initialize() takes a Context and a Configuration. You get a Configuration through the builder pattern:
- Create an instance of
Configuration.Builder - Call
setExecutor()on thatBuilderwith anExecutorthat will serve as the thread pool for theWorkManager - Call
build()on theBuilderto get theConfiguration
Prev Table of Contents Next
This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.