Saturday, July 26, 2014

Multithreading


Thread:

A thread is a lightweight sub process, a smallest unit of processing. It is a separate path of execution. It shares the memory area of process. A single process might contain multiple threads . All threads within a process share the same state and same memory space, and can communicate with each other directly, because they share the same variables.

Multithreading:

To understand multithreading, we need to understand first the difference between process and Thread. A process is a program in execution. A process may be divided into a number of independent units known as threads. A thread is a dispatchable unit of work. Threads are light-weight processes within a process. A process is a collection of one or more threads and associated system resources.



    
Multitasking :

Multitasking of two or more processes is known as process-based multitasking. Multitasking of two or more threads is known as thread-based multitasking. Process-based multitasking is totally controlled by the operating system. But thread-based multitasking can be controlled by the programmer to some extent in a program.


Now, Multithreading is a process of executing multiple threads simultaneously, or you can say, Multithreading is a technique that allows a program or a process to execute many tasks concurrently (at the same time and parallel). Java provides built-in support for multithreaded programming.                

Advantages of multithreading over multiprocessing :

  • Reduces the computation time.
  • Improves performance of an application.
  • Threads share the same address space so it saves the memory.
  • Context switching between threads is usually less expensive than between processes.
  • Cost of communication between threads is relatively low.

No comments :

Post a Comment