JAVA Threads
1. What is a Thread...?
When simply put a thread is a program's path of execution. A java program may have one or more threads.
2. Purpose of having threads
The purpose of threads is to allow the program to do multiple things at one time. This helps to make time and resource efficient programs.
Ex: One thread can do calculations while another thread prints a data sheet and some other thread could deal with user in puts at the same time.If only one thread existed in the program all above tasks should have done one after another. Thanks to threads all three task can be perform at the same time and hence make the program time efficient. And also the resources (CPU time, the memory, etc.) of the computer could be waist if the program has to wait until it take all the inputs to do calculations. This could cause the resources to be idle for some time. Threading concept helps the program to utilize all the resources it has.
Having multiple threads in a program is called as Multithreading.
Having multiple threads in a program is called as Multithreading.