Types of multitasking
Multitasking is the ability to perform more than one activity concurrently on a computer. We can further break multitasking into process based and thread based .
There are 2 different types of multitasking
- Process based multitasking
- Thread based multitasking
Process based multitasking : It allows to run two or more programs concurrently. In process based multitasking a process is the smallest part of code .
Example : Running Ms word and Ms powerpoint at a time.
Thread based multitasking : It allows to run parts of a program to run concurrently.
Example : Formatting the text and printing word document at same time .
Java supports thread based multitasking and provides built in support for multithreading.
Multitasking: Multitasking is a process of executing multiple tasks simultaneously.We use multitasking to utilize the CPU.It is a concept of performing multiple tasks over a certain period of time by executing them concurrently.Multitasking can be achieved in two ways:
1.Process based multitasking(Multiprocessing):A process has a self contained execution environment.It allows processes to run concurrently on a computer.Executing various jobs together where each job is a Seperate independent operation,is called process based multitasking.A process has a complete,private set of basic resources.Each process has its own set of memory space and allocates a Seperate memory area.A process is a heavy weight and also the communication between the process is high.Switching from one process to another requires some time for saving and loading registers,memory maps,updating lists.
Example: While we are typing a java program in editor we can also listen to audio songs by an mp3player in our system at the same time we can download a file from the net.All these jobs are executing together and independent of each other hence this is process based multitasking.The process based multitasking us best suited at OS Level.
2.Thread based multitasking(multithreading): Executing several tasks simultaneously where each task is a Seperate independent part of the same program is called Thread based multitasking and each independent part is called Thread.It is best suitable for the programmatic level.The main goal of multitasking is to make or do a better performance of the system by reducing response time.Threads share the same address space and is lightweight.Also the cost of communication between the thread is low.
The main important application areas of multithreading are developing video games,multimedia graphics,implementing animation.Java provides inbuilt support for multithreading by introducing a rich API(thread,runnable,thread group,thread local) being a programmer we have to know how to use this API and we were not responsible to define the API.