Multithreading in java
1. Advantage of Java Multithreading
- It doesn't block the user because threads are independent and you can perform multiple operations at same time
- You can perform many operations together so it saves time
- Threads are independent so it doesn't affect other threads if exception occur in a single thread
2. MultiTasking
- Multitasking is a process of executing multiple tasks simultaneously
- We use it to utilize the CPU
- Multitasking can be achieved by two ways
1) Process-based Multitasking(Multiprocessing)
2) Thread-based Multitasking(Multithreading)
1) Process-based Multitasking(Multiprocessing)
- 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...
2) Thread-based Multitasking(Multithreading)
- Threads share the same address space
- Thread is lightweight
- Cost of communication between the thread is low
3. Thread
- A thread is a lightweight sub process
- smallest unit of processing
- Threads are independent, if there occurs exception in one thread, it doesn't affect other threads
- It shares a common memory area
- Thread is executed inside the process
- There can be multiple processes inside the OS and One process can have multiple threads
- At a time one thread is executed only
'Back-End > Java_1' 카테고리의 다른 글
[Java] Creating thread (0) | 2016.10.05 |
---|---|
[Java] Life cycle of a thread (0) | 2016.10.05 |
[Java] Call by value (0) | 2016.09.13 |
[Java] Encapsulation (0) | 2016.09.12 |
[Java] Package (0) | 2016.09.12 |