Multiprocessing vs Multi threading a real world example to understand
This link contains the basic idea on ThreadPoolExecutor
To know detail on WeakReference
Executor is an interface used to decouple task submission from task execution.
ExecutorService is an interface which implements Executor interface and provides additional methods which allow you
-
to shutdown the service and
-
track progress and
-
cancel submitted tasks.
ExecutorService mExecutorService = new ThreadPoolExecutor(NUMBER_OF_CORES, NUMBER_OF_CORES*2, KEEP_ALIVE_TIME, KEEP_ALIVE_TIME_UNIT, mTaskQueue, new BackgroundThreadFactory());
ThreadPoolExecutor maintains task queue and thread pool. It picks tasks from queue and executes it using a free thread from the thread pools it maintains.
Task producer submits tasks to task queue.
ThreadPoolExecutor downloadThreadPool =
new ThreadPoolExecutor(NUMBER_OF_CORES,
NUMBER_OF_CORES*2,
KEEP_ALIVE_TIME,
KEEP_ALIVE_TIME_UNIT,
mTaskQueue,
new BackgroundThreadFactory());
- package (uploader)
Here it is a demo file upload task. Actually we don't upload any file but create an environment that will upload 4 file parallely.
Using ThreadPool Manager, RxJava, Callable and Future to make a complete package.