InterviewSolution
| 1. |
Need of Thread in Java |
|
Answer» Threads in Java help to achieve parallelism in a program. This means that multiple operations can be performed at the same time using multithreading. The most IMPORTANT usage of threads can be achieved using multithreading. This means that multiple tasks can be done simultaneously using multithreading. Some of the major uses of multithreading in Java are given as follows:
The response time for a particular problem can be reduced by dividing it into smaller CHUNKS and assigning each of these chunks to a thread. This means that multiple threads can be used to solve the problem in a relatively lesser time.
Multiple tasks can run in parallel using multithreading. An example of this is event handling or drawing which can be performed at the same time using multiple threads. Also, multiple threads are REQUIRED in a Graphical User Interface as a thread is performing a particular function, other threads are required for more user tasks as the GUI cannot be frozen.
In a client server application, many clients can connect to the server using multiple threads. This means that a client does not have to wait until the request of the previous client has been serviced by the server.
Threads can be used to utilize the full CPU power and INCREASE the throughput of the system. If there are multiple cores to the CPU, then multiple threads are required to run in parallel across these cores to optimize the system performance. |
|