Java Multitasking
-
When a single CPU performs multiple tasks (program, process, task, threads) at the same time, this is referred to as multitasking. To perform multitasking, the CPU switches between these tasks frequently so that the user can interact with each program at the same time.
-
A multitasking operating system allows multiple users to share the system at the same time. As we saw, the CPU rapidly switches between tasks, so switching from one user to the next takes some time. This gives the user the impression that the entire computer system is dedicated to him.
-
When several users share a multitasking operating system, CPU scheduling and multiprogramming allow each user to have at least a small portion of the Multitasking OS and at least one program in memory for execution.
Java Multithreading
-
Multithreading differs from multitasking in that multitasking allows multiple tasks to be executed concurrently, whereas Multithreading allows multiple threads of a single task (program, process) to be executed concurrently by the CPU.
-
Before we get into multithreading, let's define a thread. A thread is a basic execution unit that has its own program counter, register set, and stack but shares the process's code, data, and file. A process can have multiple threads running at the same time, and the CPU switches between them so frequently that the user believes all threads are running at the same time, which is known as multithreading.
-
Multithreading improves system responsiveness because if one thread of an application is not responding, the other will, and the user will not have to sit idle. Multithreading enables resource sharing because threads belonging to the same process can share the process's code and data, and it enables a process to have multiple threads active in the same address space at the same time.
-
Creating a new process is more expensive because the system must allocate separate memory and resources to each process, whereas creating threads is simple because it does not require allocating separate memory and resources for threads of the same process.
Difference between StringBuffer and String class
Difference between StringBuffer and String class are mention below
S.no |
Multitasking |
Multithreading |
1. |
Multitasking allows the CPU to perform multiple tasks at the same time. |
Multithreading allows the CPU to run multiple threads of a process at the same time. |
2. |
When multitasking, the CPU frequently switches between programs. |
The CPU frequently switches between threads in multithreading. |
3. |
Each program that the CPU is executing in a multitasking system requires its own memory and resources. |
When a multithreading system allocates memory to a process, multiple threads of that process share the same memory and resources. |
4. |
The CPU is used in multitasking to execute multiple tasks at once. |
A CPU is also provided in multithreading in order to execute multiple threads from a process at the same time. |
5. |
Multitasking is slower than multithreading. |
Multithreading, on the other hand, is faster. |
6. |
Terminating a process takes longer when multitasking. |
Thread termination takes less time in multithreading. |
7. |
Multitasking allows for isolation and memory protection. |
In multithreading, isolation and memory protection do not exist. |
Post your comment