Multithreading
Java is a multithreaded programming language which means we can develop
multi Threaded program using Java. A multi threaded program contains two or
more parts that can run concurrently and each part can handle different task at
the same time making optimal use of the available resources specially when your
computer has multiple CPUs.
By definition multitasking is when multiple processes share common
processing resources such as a CPU. Multi threading extends the idea of
multitasking into applications where you can subdivide specific operations
within a single application into individual threads. Each of the threads can
run in parallel.
Multi threading enables you to write in a way where multiple activities
can proceed concurrently in the same program.
Life Cycle of a Thread:
A thread goes through various stages in its life cycle. For example, a
thread is created, started, runs, and then destroyed. The above diagram shows
complete life cycle of a thread.
Above- mentioned stages are explained here:
New: A new thread begins its life cycle in the new state. It remains in
this state until the program starts the thread. It is also referred to as a
born thread.
Runnable: After a newly created thread is started, the thread becomes
runnable. A thread in this state is considered to be executing its task.
Waiting: Sometimes, a thread transitions to the Waiting state while the
thread waits for another thread to perforMa task. A thread transitions back to
the runnable state only when another thread signals the Waiting thread to
continue executing.
Timed Waiting: A runnable thread can enter the Timed Waiting state for a
specified interval of time. A thread, in this state transitions back to the
runnable state when that time interval expires or when the event it is Waiting
for occurs.
Terminated: A runnable thread enters the terminated state when it
completes its task or otherwise terminates.
Related Topics
Privacy Policy, Terms and Conditions, DMCA Policy and Compliant
Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.