Simply we can say multi threading is a kind of specialized form of multi tasking. In a thread based multitasking environment, the thread is a smallest unit of dispatchable code. In a single program we do two or more tasks at a time (simultaneously).
Take an example of Microsoft word, where it is doing the spell checking at the same time we writing the document. The writing of document, and checking spells are two different threads which is running simultaneously.
Do not get confused multi threading by multiprocessing. This difference is clearly visible in the below image.
Advantages of Threads
Take an example of Microsoft word, where it is doing the spell checking at the same time we writing the document. The writing of document, and checking spells are two different threads which is running simultaneously.
Do not get confused multi threading by multiprocessing. This difference is clearly visible in the below image.
Advantages of Threads
- Light weight process
- Thread creation is 10-100 times faster than the process creation (because when each and every process is creating it need to be occupied a separate memory slots where as in threads uses the current memory slots)
- Lower context switching overhead
- All threads within a process shares same global memory
Main Thread
When a Java Program starts up, one thread begins running immediately, usually called the Main Thread. This main thread is important for two reasons:
- It is the thread from where other child thread will be created
- Often it must be the last thread to finish the execution because it performs various shutdown actions.
No comments:
Post a Comment