Multi Threading Programming In Java
What is the multi threading programming that we used is Java, hear this.. Java is actually a multi-threaded programming language and by that Java can let us develop a multi-threaded program.
Do you know what a multi-threaded program is? well a multi-threaded program contains two or more than two parts. Which runs concurrently and each of that one part can handle different task (i.e codes that contains methods, constructors etc) at the same equal time. This can actually improves the optimal use of the available resource, if you have multiple CPUs.
Basically multi threading programming takes the idea of multi tasking. Which is “doing more than 1 activities at the same time”. Multi tasking in our terms it means when a multiple processes share a common process resource such as a CPU.
Life Cycle of a Thread
Look at this 5 cycle of a Thread : First of all is New Thread. In this cycle a thread begins its circle of life / life cycle in a new state. It will not change to another state until the program starts the thread. Another name that I found is a little bit funny, it is ” born thread”.
- Runnable – After a ” born thread” is started in its program. The thread becomes “runnable”, A thread in this kind of state is considered to be executing/doing its task.
- Waiting State . Sometimes, the transitions of a thread state while the thread is waiting for another thread to perform its task . A thread transitions back to “runnable” state is only when another thread signals to another thread. That thread is the waiting thread to continue executing.
- Timed Waiting – A thread that is in a runnable state can enter “timed waiting state” for a specified interval of time. The thread that is still in this state transitions back to “runnable state” when the time interval expires or when an event of its is waiting to occurs.
- Terminated(Dead) – After all of those life cycle, the thread come to the of its circle of life and enter the terminated state when the thread completes its task or otherwise terminates.
The programming language that I specialize in is Java, because I think Java programming language is more universal and of course because I like it regardless of any reason.