230 likes | 748 Views
MULTITHREADING PROGRAMMING. MULTITASKING It is same as multithreading. Multitasking in java is a process of executing multiple tasks simultaneously. Multithreading and Multiprocessing both are used to achieve multitasking. In multitasking we have two methods.
E N D
MULTITASKING It is same as multithreading. Multitasking in java is a process of executing multiple tasks simultaneously. Multithreadingand Multiprocessing both are used to achieve multitasking. In multitasking we have two methods. Process based Multitasking(Multiprogramming) Thread based Multitasking(multithreading)
Process based Multitasking(Multiprogramming) Each process has an address in memory . A process is a heavyweight. Cost of communication between the process is high. Thread based Multitasking(multithreading) Threads share the same address space A thread is lightweight. Cost of communication between the thread is low
ADVANTAGES OF MULTITHREAD It doesn’t block the user because threads are independent. The user can perform many operation together, so it saves time. Threads are independent, so it doesn’t affect other threads.
SINGLE THREADED PROGRAM Single thread used to perform only one task. A thread is a lightweight sub-process, the smallest unit of processing. class ABC { …. public void run(..) { … .. } }
MULTITHREADING PROGRAMMING Multithreading in java is a process of executing multiple threads simultaneously. Its also called as multitasking.
A Multithreaded Program Main Thread start start start Thread A Thread B Thread C Threads may switch or exchange data/results
Threads Concept Multiple threads on multiple CPUs Multiple threads sharing a single CPU