Wednesday, 8 February 2017

MULTITASKING AND MULTITHREADING IN JAVA

Executing multiple tasks at a time is called multitasking. Example – While typing a program, we can download a file, we can listen to music. It is called multitasking. There are two types of multitasking. They are –

1. Process based multitasking – Executing several tasks simultaneously is called process based multitasking. Here each task is a separate independent process. While tying a java program in the editor we can listen to mp3 player audio songs and at the same time we can download the file from the net. All these tasks are independent of each other and executed simultaneously, hence it is process based multitasking. These types of multitasking is best suitable at operating system level but not at programmer level.

2. Thread based multitasking – Executing multiple task concurrently is called thread based multitasking. Here each task is a separate independent part of a single process. This part is called thread. This type of multitasking is developed at programmer level.

Advantage 0f Multitasking – Whether it is process based or thread based the main advantage of multitasking is we can reduce response time so that performance of the system will be improved.


Difference between multitasking and multithreading –

1. Multitasking is heavy weight as switching between contexts is slow because each process is stored at separate address.
2. Multithreading is light weight as switching between contexts is fast as each process supports for creating custom threads by providing API-Runnable, Thread, ThreadGroup.


Sequential execution v/s Concurrent execution

1. Sequential execution means single thread execution which takes more time to complete all methods execution.
2. Whereas Concurrent execution means multithreading execution which takes less to complete all methods execution. To have concurrent execution, developer must create user defined thread in the program. 

No comments:

Post a Comment