Skip to content

Latest commit

 

History

History
62 lines (38 loc) · 2.62 KB

Readme.md

File metadata and controls

62 lines (38 loc) · 2.62 KB

ACK

Multiprocessing vs Multi threading a real world example to understand

Process vs Thread

This link contains the basic idea on ThreadPoolExecutor

To know detail on WeakReference

Multitasking

MultiThreading

Executor

Executor is an interface used to decouple task submission from task execution.

ExecutorService

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

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());

Diagram

image

Output

image

  • 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.