MULTITHREADING
- process of executing multiple threads simultaneously.
- Thread is basically a light weight sub-process , a smallest unit of processing. Multiprocessing and multi threading , both are used to achieve multiprocessing.
- threads share a common memory, and context switching between threads takes less time than process.
- Java multi threading mostly used in games and animation etc.
- Advantages:
2. you can peform many operations together to save time
3. Threads are independent it doesn't effect other threads if exception occur in single thread.
- Multi tasking:
1. process based multitasking(multiprocessing)
2. thread based multitasking(multithreading)
1.process based multitasking:
- Each process have its own address in memory i.e. each process allocates separate memory area.
- Process is heavyweight.
- Cost of communication between the process is high.
- Switching from one process to another require some time for saving and loading registers, memory maps, updating lists etc.
- Each process have its own address in memory i.e. each process allocates separate memory area.
- Process is heavyweight.
- Cost of communication between the process is high.
- Switching from one process to another require some time for saving and loading registers, memory maps, updating lists etc.
- At least one process is required for each thread.
- Thread in JAVA:
Threads are independent , if there occurs exception in one thread , it doesn't effect other threads. it shares a common memory area.
As shown in the above figure, thread is executed inside the process. There is context-switching between the threads. There can be multiple processes inside the OS and one process can have multiple threads.
at a time only one thread executes.
Comments
Post a Comment