{"id":25531490,"date":"2022-07-01T20:00:03","date_gmt":"2022-07-01T14:30:03","guid":{"rendered":"https:\/\/entri.app\/blog\/?p=25531490"},"modified":"2022-11-19T17:06:03","modified_gmt":"2022-11-19T11:36:03","slug":"life-cycle-of-a-thread-in-java-an-overview","status":"publish","type":"post","link":"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/","title":{"rendered":"Life Cycle of a Thread in Java: An Overview"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_79_2 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69d3cc0e6548c\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69d3cc0e6548c\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/#What_are_the_Different_States_of_a_Thread\" >What are the Different States of a Thread?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/#Java_Program_for_the_Demonstrating_Thread_States\" >Java Program for the Demonstrating Thread States<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<p>Java threads run on the JVM (Java Virtual Machine). A thread methods in java is an execution context that can simultaneously execute different tasks, but only one task at a time. While the GIL (Global Interpreter Lock) ensures that only one thread runs at a time, threads still perform better than processes with real parallelism and real concurrency because multiple threads can be running at the same time in <a href=\"https:\/\/entri.app\/blog\/getter-and-setter-in-java-a-complete-guide\/\" target=\"_blank\" rel=\"noopener\">different parts<\/a> of the code. To write efficient multithreaded code, it\u2019s important to understand what\u2019s going on inside your Thread objects as they\u2019re executed on the JVM. <span data-slate-fragment=\"JTVCJTdCJTIydHlwZSUyMiUzQSUyMnBhcmFncmFwaCUyMiUyQyUyMmNoaWxkcmVuJTIyJTNBJTVCJTdCJTIydGV4dCUyMiUzQSUyMkElMjB0aHJlYWQlMkMlMjBzb21ldGltZXMlMjBjYWxsZWQlMjBhJTIwbGlnaHR3ZWlnaHQlMjBwcm9jZXNzJTJDJTIwaXMlMjB0aGUlMjBzbWFsbGVzdCUyMHVuaXQlMjBvZiUyMGV4ZWN1dGlvbiUyMGluJTIwSmF2YSUyMGFuZCUyMG1vc3QlMjBvdGhlciUyMG9wZXJhdGluZyUyMHN5c3RlbXMuJTIwSXQlMjByZXByZXNlbnRzJTIwYW4lMjBleGVjdXRpb24lMjBmbG93JTIwb2YlMjBpbnN0cnVjdGlvbnMlMjBwZXJmb3JtZWQlMjBieSUyMHRoZSUyMGNvbXB1dGVyJUUyJTgwJTk5cyUyMHByb2Nlc3NvcihzKS4lMjBUaHJlYWRzJTIwYXJlJTIwdGhlJTIwZXhlY3V0aW9uJTIwY29udGV4dCUyMG9mJTIwYWN0aW9ucyUyMHRoYXQlMjBhcmVuJUUyJTgwJTk5dCUyMHJlbGF0ZWQlMjB0byUyMGVhY2glMjBvdGhlciUyMGJ1dCUyMG11c3QlMjBiZSUyMHBlcmZvcm1lZCUyMGF0JTIwdGhlJTIwc2FtZSUyMHRpbWUuJTIwRm9yJTIwZXhhbXBsZSUyQyUyMHR3byUyMHRocmVhZHMlMjBtaWdodCUyMHJ1biUyMGluJTIwcGFyYWxsZWwlMjBpbiUyMG9yZGVyJTIwdG8lMjBjYWxjdWxhdGUlMjB2YWx1ZXMlMjBmcm9tJTIwdHdvJTIwZGlmZmVyZW50JTIwc2V0cyUyMG9mJTIwZGF0YSUyMGZhc3RlciUyMHRoYW4lMjBydW5uaW5nJTIwdGhlbSUyMHNlcXVlbnRpYWxseSUzQiUyMGFub3RoZXIlMjB0aHJlYWQlMjBtaWdodCUyMG5lZWQlMjB0byUyMHdhaXQlMjB1bnRpbCUyMHRoZSUyMHJlc3VsdHMlMjBvZiUyMG9uZSUyMHRocmVhZCUyMGFyZSUyMGZpbmlzaGVkJTIwYmVmb3JlJTIwaXQlMjBjYW4lMjBjb250aW51ZSUyMGl0cyUyMG93biUyMGNhbGN1bGF0aW9ucy4lMjIlN0QlNUQlN0QlNUQ=\">A thread, sometimes called a lightweight process, is the smallest unit of execution in Java and most other operating systems. It represents an execution flow of instructions performed by the computer\u2019s processor(s).<\/span><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/bit.ly\/3ELmCiA\">Get the latest updates on java programming in the Entri app<\/a><\/p>\n<p><span data-slate-fragment=\"JTVCJTdCJTIydHlwZSUyMiUzQSUyMnBhcmFncmFwaCUyMiUyQyUyMmNoaWxkcmVuJTIyJTNBJTVCJTdCJTIydGV4dCUyMiUzQSUyMkElMjB0aHJlYWQlMkMlMjBzb21ldGltZXMlMjBjYWxsZWQlMjBhJTIwbGlnaHR3ZWlnaHQlMjBwcm9jZXNzJTJDJTIwaXMlMjB0aGUlMjBzbWFsbGVzdCUyMHVuaXQlMjBvZiUyMGV4ZWN1dGlvbiUyMGluJTIwSmF2YSUyMGFuZCUyMG1vc3QlMjBvdGhlciUyMG9wZXJhdGluZyUyMHN5c3RlbXMuJTIwSXQlMjByZXByZXNlbnRzJTIwYW4lMjBleGVjdXRpb24lMjBmbG93JTIwb2YlMjBpbnN0cnVjdGlvbnMlMjBwZXJmb3JtZWQlMjBieSUyMHRoZSUyMGNvbXB1dGVyJUUyJTgwJTk5cyUyMHByb2Nlc3NvcihzKS4lMjBUaHJlYWRzJTIwYXJlJTIwdGhlJTIwZXhlY3V0aW9uJTIwY29udGV4dCUyMG9mJTIwYWN0aW9ucyUyMHRoYXQlMjBhcmVuJUUyJTgwJTk5dCUyMHJlbGF0ZWQlMjB0byUyMGVhY2glMjBvdGhlciUyMGJ1dCUyMG11c3QlMjBiZSUyMHBlcmZvcm1lZCUyMGF0JTIwdGhlJTIwc2FtZSUyMHRpbWUuJTIwRm9yJTIwZXhhbXBsZSUyQyUyMHR3byUyMHRocmVhZHMlMjBtaWdodCUyMHJ1biUyMGluJTIwcGFyYWxsZWwlMjBpbiUyMG9yZGVyJTIwdG8lMjBjYWxjdWxhdGUlMjB2YWx1ZXMlMjBmcm9tJTIwdHdvJTIwZGlmZmVyZW50JTIwc2V0cyUyMG9mJTIwZGF0YSUyMGZhc3RlciUyMHRoYW4lMjBydW5uaW5nJTIwdGhlbSUyMHNlcXVlbnRpYWxseSUzQiUyMGFub3RoZXIlMjB0aHJlYWQlMjBtaWdodCUyMG5lZWQlMjB0byUyMHdhaXQlMjB1bnRpbCUyMHRoZSUyMHJlc3VsdHMlMjBvZiUyMG9uZSUyMHRocmVhZCUyMGFyZSUyMGZpbmlzaGVkJTIwYmVmb3JlJTIwaXQlMjBjYW4lMjBjb250aW51ZSUyMGl0cyUyMG93biUyMGNhbGN1bGF0aW9ucy4lMjIlN0QlNUQlN0QlNUQ=\">Threads are the execution context of actions that aren\u2019t related to each other but must be performed at the same time. For example, two threads might run in parallel in order to calculate values from two different sets of data faster than running them sequentially; another thread method in java might need to wait until the results of one thread are finished before it can continue its <a href=\"https:\/\/entri.sng.link\/Bcofz\/uu8c\/w409\">own calculations<\/a>. A thread in Java has a finite life cycle, with different states it goes through during its lifetime, each requiring different actions to be taken by the programmer. Following is an overview of the life cycle of a thread in Java. As you read on, you\u2019ll understand why and when certain steps are executed, and how they affect the behavior of your program.<\/span><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/bit.ly\/3ELmCiA\">To know more about java programming in the Entri app<\/a><\/p>\n<h2><span class=\"ez-toc-section\" id=\"What_are_the_Different_States_of_a_Thread\"><\/span><strong>What are the Different States of a Thread?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span data-slate-fragment=\"JTVCJTdCJTIydHlwZSUyMiUzQSUyMnBhcmFncmFwaCUyMiUyQyUyMmFsaWduJTIyJTNBJTIyJTIyJTJDJTIyY2hpbGRyZW4lMjIlM0ElNUIlN0IlMjJ0ZXh0JTIyJTNBJTIyQSUyMHRocmVhZCUyMGluJTIwSmF2YSUyMGNhbiUyMGV4aXN0JTIwaW4lMjBhbnklMjBvbmUlMjBvZiUyMHRoZSUyMGZvbGxvd2luZyUyMHN0YXRlcyUyMGF0JTIwYW55JTIwZ2l2ZW4lMjBtb21lbnQlMjIlN0QlNUQlN0QlNUQ=\">A thread in Java can exist in any one of the following states at any given moment<\/span><\/p>\n<ol class=\"points\">\n<li>New<\/li>\n<li>Active<\/li>\n<li>Blocked \/ Waiting<\/li>\n<li>Timed Waiting<\/li>\n<li>Terminated<\/li>\n<\/ol>\n<h3><strong>1)New:<\/strong><\/h3>\n<p><span data-slate-fragment=\"JTVCJTdCJTIydHlwZSUyMiUzQSUyMnBhcmFncmFwaCUyMiUyQyUyMmFsaWduJTIyJTNBJTIyJTIyJTJDJTIyY2hpbGRyZW4lMjIlM0ElNUIlN0IlMjJ0ZXh0JTIyJTNBJTIyV2hlbmV2ZXIlMjBhJTIwbmV3JTIwdGhyZWFkJTIwaXMlMjBjcmVhdGVkJTJDJTIwaXQlMjBpcyUyMGFsd2F5cyUyMGluJTIwdGhlJTIwaW5pdGlhbCUyMHN0YXRlLiUyMEZvciUyMGElMjB0aHJlYWQlMjBpbiUyMHRoZSUyMGluaXRpYWwlMjBzdGF0ZSUyQyUyMHRoZSUyMGNvZGUlMjBoYXMlMjBub3QlMjBiZWVuJTIwZXhlY3V0ZWQlMjB5ZXQlMjBhbmQlMjB0aHVzJTIwaGFzJTIwbm90JTIwYmVndW4lMjBpdHMlMjBleGVjdXRpb24uJTIyJTdEJTVEJTdEJTVE\">Whenever a new thread is created, it is always in the initial state. For a thread in the initial state, the code has not been executed yet and thus has not begun its execution.<\/span><\/p>\n<h3><strong>2)Active:<\/strong><\/h3>\n<p><span data-slate-fragment=\"JTVCJTdCJTIydHlwZSUyMiUzQSUyMnBhcmFncmFwaCUyMiUyQyUyMmFsaWduJTIyJTNBJTIyJTIyJTJDJTIyY2hpbGRyZW4lMjIlM0ElNUIlN0IlMjJ0ZXh0JTIyJTNBJTIyV2hlbiUyMGElMjB0aHJlYWQlMjBpbnZva2VzJTIwdGhlJTIwc3RhcnQoKSUyMG1ldGhvZCUyQyUyMGl0JTIwbW92ZXMlMjBmcm9tJTIwdGhlJTIwbmV3JTIwc3RhdGUlMjB0byUyMHRoZSUyMGFjdGl2ZSUyMHN0YXRlLiUyMFRoZSUyMGFjdGl2ZSUyMHN0YXRlJTIwaW5jbHVkZXMlMjB0d28lMjBzdGF0ZXMlM0IlMjBvbmUlMjBpcyUyMHJ1bm5hYmxlJTJDJTIwYW5kJTIwdGhlJTIwb3RoZXIlMjBpcyUyMHJ1bm5pbmcuJTIyJTdEJTVEJTdEJTVE\">When a thread invokes the start() method, it moves from the new state to the active state. The active state includes two states; one is runnable, and the other is running.<\/span><\/p>\n<p><strong>Runnable:<\/strong><\/p>\n<p><span data-slate-fragment=\"JTVCJTdCJTIydHlwZSUyMiUzQSUyMnBhcmFncmFwaCUyMiUyQyUyMmFsaWduJTIyJTNBJTIyJTIyJTJDJTIyY2hpbGRyZW4lMjIlM0ElNUIlN0IlMjJ0ZXh0JTIyJTNBJTIyQSUyMHRocmVhZCUyMG1vdmVzJTIwZnJvbSUyMHRoZSUyMHdhaXRpbmclMjBzdGF0ZSUyMHRvJTIwYSUyMHJ1bm5hYmxlJTIwc3RhdGUlMjB3aGVuJTIwaXQlMjBoYXMlMjBiZWVuJTIwc2V0JTIwdXAlMjBhbmQlMjBoYXMlMjBiZWNvbWUlMjByZWFkeSUyMHRvJTIwZXhlY3V0ZS4lMjBBJTIwdGhyZWFkJTIwd2lsbCUyMHN0YXklMjBpbiUyMHRoaXMlMjBzdGF0ZSUyMHVudGlsJTIwYW5vdGhlciUyMG9uZSUyMG5lZWRzJTIwaXRzJTIwdGltZSUyMHNsb3QlMkMlMjBhdCUyMHdoaWNoJTIwcG9pbnQlMjBpdCUyMHdpbGwlMjB0cmFuc2l0aW9uJTIwYmFjayUyMHRvJTIwdGhlJTIwd2FpdGluZyUyMHN0YWdlLiUyMFRocmVhZHMlMjBhcmUlMjBhbHNvJTIwcHJpb3JpdGl6ZWQlMjBhY2NvcmRpbmclMjB0byUyMGNlcnRhaW4lMjBjcml0ZXJpYSUyMC0lMjB0aGUlMjBwcmlvcml0eSUyMGRldGVybWluZXMlMjB3aGF0JTIwb3JkZXIlMjB0aGV5J2xsJTIwYmUlMjBleGVjdXRlZCUyMGluJTIwcmVsYXRpdmUlMjB0byUyMGVhY2glMjBvdGhlciUzQiUyMGhpZ2hlci1wcmlvcml0eSUyMHRocmVhZHMlMjB3aWxsJTIwYWx3YXlzJTIwZ2V0JTIwcHJlY2VkZW5jZSUyMG92ZXIlMjBsb3dlci1wcmlvcml0eSUyMG9uZXMlMjBpZiUyMHR3byUyMHRocmVhZHMlMjBhcmUlMjBzaW11bHRhbmVvdXNseSUyMHNjaGVkdWxlZCUyMGZvciUyMGV4ZWN1dGlvbi4lMjIlN0QlNUQlN0QlNUQ=\">A thread moves from the waiting state to a runnable state when it has been set up and has become ready to execute. A thread will stay in this state until another one needs its time slot, at which point it will transition back to the waiting stage. Threads are also prioritized according to certain criteria &#8211; the priority determines what order they&#8217;ll be executed in relative to each other; higher-priority threads will always get precedence over lower-priority ones if two threads are simultaneously scheduled for execution. A process using multi-threading shares a predetermined amount of time to each thread. Every thread is assigned a set amount of seconds during which it runs until its allotted timeframe has elapsed and then willingly yields control back to another thread. When this happens, all threads that wish to run but are not currently running wait in an ordered line inside the code called runnable. Once they are given permission, these threads take their turn completing the necessary function until they give up control again.<\/span><\/p>\n<p><strong>Running:<\/strong><\/p>\n<p>When the thread gets the CPU, it moves from the runnable to the running state. Generally, the most common change in the state of a thread is from runnable to running and again back to runnable.<\/p>\n<h3><strong>3)Blocked or Waiting:<\/strong><\/h3>\n<p>Whenever a thread is inactive for a span of time (not permanently) then, either the thread is in the blocked state or is in the waiting state. <span data-slate-fragment=\"JTVCJTdCJTIydHlwZSUyMiUzQSUyMnBhcmFncmFwaCUyMiUyQyUyMmFsaWduJTIyJTNBJTIyJTIyJTJDJTIyY2hpbGRyZW4lMjIlM0ElNUIlN0IlMjJ0ZXh0JTIyJTNBJTIyV2hlbiUyMG9uZSUyMHRocmVhZCUyMChjYWxsJTIwaXQlMjBUaHJlYWQlMjBBKSUyMG5lZWRzJTIwdG8lMjBwcmludCUyMHNvbWV0aGluZyUyQyUyMGJ1dCUyMGFub3RoZXIlMjB0aHJlYWQlMjBpcyUyMGFscmVhZHklMjBwcmludGluZyUyMHNvbWV0aGluZyUyMG9uJTIwdGhlJTIwcHJpbnRlciUyMGF0JTIwdGhlJTIwc2FtZSUyMHRpbWUlMkMlMjB0aGVuJTIwVGhyZWFkJTIwQSUyMGhhcyUyMHRvJTIwd2FpdCUyMGZvciUyMFRocmVhZCUyMEIlMjBiZWZvcmUlMjBkb2luZyUyMGFueXRoaW5nLiUyMFNvJTIwd2hlbiUyMFRocmVhZCUyMEElMjBpcyUyMGJsb2NrZWQlMkMlMjBpdCUyMGNhbm5vdCUyMGV4ZWN1dGUlMjBhbnklMjBjb2RlJTIwYW5kJTIwc28lMjBkb2VzJTIwbm90JTIwdGFrZSUyMHVwJTIwYW55JTIwQ1BVJTIwY3ljbGVzLiUyMFRoaXMlMjBtZWFucyUyMHRoYXQlMjB3aGlsZSUyMFRocmVhZCUyMEElMjBtaWdodCUyMGJlJTIwc2l0dGluZyUyMHRoZXJlJTIwd2FpdGluZyUyQyUyMGl0JTIwaXNuJ3QlMjBjb25zdW1pbmclMjBhbnklMjByZXNvdXJjZXMuJTIwV2hlbiUyMHRoZSUyMHNjaGVkdWxlciUyMHdha2VzJTIwdXAlMjB3aGF0ZXZlciUyMHdhcyUyMGluJTIwYSUyMHdhaXRpbmclMjBzdGF0ZSUyMChzdWNoJTIwYXMlMjBUaHJlYWQlMjBBKSUyQyUyMHRoZW4lMjB0aGluZ3MlMjBhcmUlMjBiYWNrJTIwdG8lMjBub3JtYWwlMjBhZ2Fpbi4lMjIlN0QlNUQlN0QlNUQ=\">When one thread (call it Thread A) needs to print something, but another thread is already printing something on the printer at the same time, then Thread A has to wait for Thread B before doing anything. So when Thread A is blocked, it cannot execute any code and so does not take up any CPU cycles. This means that while Thread A might be sitting there waiting, it isn&#8217;t consuming any resources. When the scheduler wakes up whatever was in a waiting state (such as Thread A), then things are back to normal again.<\/span><\/p>\n<p><span data-slate-fragment=\"JTVCJTdCJTIydHlwZSUyMiUzQSUyMnBhcmFncmFwaCUyMiUyQyUyMmFsaWduJTIyJTNBJTIyJTIyJTJDJTIyY2hpbGRyZW4lMjIlM0ElNUIlN0IlMjJ0ZXh0JTIyJTNBJTIyV2hlbiUyMHRoZSUyMG1haW4lMjB0aHJlYWQlMjBpbnZva2VzJTIwdGhlJTIwSm9pbigpJTIwbWV0aG9kJTIwdGhlbiUyQyUyMGl0JTIwaXMlMjBzYWlkJTIwdGhhdCUyMHRoZSUyME1haW4lMjBUaHJlYWQlMjBpcyUyMGluJTIwdGhlJTIwV2FpdGluZyUyMFN0YXRlLiUyMFRoZSUyME1haW4lMjBUaHJlYWQlMjB0aGVuJTIwd2FpdHMlMjBmb3IlMjBhbGwlMjBvZiUyMGl0cyUyMENoaWxkJTIwVGhyZWFkcyUyMHRvJTIwY29tcGxldGUlMjB0aGVpciUyMHRhc2tzLiUyME9uY2UlMjBhbGwlMjBvZiUyMGl0cyUyMENoaWxkJTIwVGhyZWFkcyUyMGFyZSUyMGRvbmUlMjB3aXRoJTIwdGhlaXIlMjB0YXNrJTJDJTIwYSUyME5vdGlmaWNhdGlvbiUyMHdpbGwlMjBiZSUyMHNlbnQlMjB0byUyMHRoZSUyME1haW4lMjBUaHJlYWQlMjBhbmQlMjBpdCUyMHdpbGwlMjBtb3ZlJTIwYmFjayUyMGludG8lMjBBY3RpdmUlMjBTdGF0dXMlMjIlN0QlNUQlN0QlNUQ=\">When the main thread invokes the Join() method then, it is said that the Main Thread is in the Waiting State. The Main Thread then waits for all of its Child Threads to complete their tasks. Once all of its Child Threads are done with their task, a Notification will be sent to the Main Thread and it will move back into Active Status. If there are a lot of threads in the waiting or blocked state, then it is the duty of the thread scheduler to determine which thread to choose and which one to reject, and the chosen thread is then given the opportunity to run.<\/span><\/p>\n<h3><strong>4)Timed Waiting:<\/strong><\/h3>\n<p><span data-slate-fragment=\"JTVCJTdCJTIydHlwZSUyMiUzQSUyMnBhcmFncmFwaCUyMiUyQyUyMmFsaWduJTIyJTNBJTIyJTIyJTJDJTIyY2hpbGRyZW4lMjIlM0ElNUIlN0IlMjJ0ZXh0JTIyJTNBJTIyV2FpdGluZyUyMGZvciUyMHNvbWVvbmUlMjBvciUyMHNvbWV0aGluZyUyMGNhbiUyMG9mdGVuJTIwYmUlMjBjb3N0bHkuJTIwRm9yJTIwaW5zdGFuY2UlMkMlMjBpZiUyMFRocmVhZCUyMEElMjBlbnRlcnMlMjBhJTIwY3JpdGljYWwlMjBzZWN0aW9uJTIwb2YlMjBjb2RlJTIwYW5kJTIwcmVmdXNlcyUyMHRvJTIwbGVhdmUlMkMlMjBhbm90aGVyJTIwdGhyZWFkLSUyMHNheSUyMFRocmVhZCUyMEItJTIwd2lsbCUyMGhhdmUlMjB0byUyMHdhaXQlMjBpbmRlZmluaXRlbHklMjB1bnRpbCUyMGl0JTIwaXMlMjBncmFudGVkJTIwYWNjZXNzLiUyMFRoaXMlMjBjb3VsZCUyMGxlYWQlMjB0byUyMHN0YXJ2YXRpb24lMjBpZiUyMG5vdCUyMGhhbmRsZWQlMjBwcm9wZXJseSUzQiUyMGx1Y2tpbHklMjB0aGVyZSUyMGFyZSUyMHNvbHV0aW9ucyUyMGFnYWluc3QlMjB0aGlzJTIwcHJvYmxlbS4lMjBPbmUlMjBzb2x1dGlvbiUyMGlzJTIwdGhlJTIwdXNlJTIwb2YlMjB0aW1lcnMlMjB0aGF0JTIwcHV0JTIwVGhyZWFkJTIwQiUyMGluJTIwc3RhbmRieSUyMG1vZGUlMjB1bnRpbCUyMHRpbWVvdXQlMjBleHBpcmVzJTNCJTIwdGhpcyUyMHdvdWxkJTIwYWxsb3clMjBvdGhlciUyMHRocmVhZHMlMjB0byUyMG1vdmUlMjBmb3J3YXJkJTIwd2hpbGUlMjBzdGlsbCUyMG1haW50YWluaW5nJTIwYmFsYW5jZSUyMHdpdGglMjBUaHJlYWQlMjBBLiUyMElmJTIweW91JTIwdGFrZSUyMHRvbyUyMGxvbmclMjBvbiUyMG9uZSUyMHRhc2slMjB0aGVuJTIwdGhlcmUncyUyMG5vJTIwdGVsbGluZyUyMHdoYXQlMjBtaWdodCUyMGhhcHBlbiUyMC0lMjB5b3UlMjBuZXZlciUyMGtub3clMjB3aG8lMjBuZWVkcyUyMHlvdSUyMG9yJTIwd2hlcmUlMjB0aGUlMjBuZXh0JTIwb3Bwb3J0dW5pdHklMjB3aWxsJTIwYXJpc2UhJTIwU28lMjBhbHdheXMlMjBrZWVwJTIweW91ciUyMGV5ZXMlMjBvcGVuJTIwYW5kJTIweW91ciUyMGVhcnMlMjBwZWVsZWQlMjBqdXN0JTIwaW4lMjBjYXNlJTIwc29tZW9uZSUyMG5lZWRzJTIwc29tZSUyMGhlbHAlMjBvciUyMHdhbnRzJTIwYWR2aWNlISUyMiU3RCU1RCU3RCU1RA==\">Waiting for someone or something can often be costly. For instance, if Thread A enters a critical section of code and refuses to leave, another thread- say Thread B- will have to wait indefinitely until it is granted access. This could lead to starvation if not handled properly; luckily there are solutions against this problem. One solution is the use of timers that put Thread B in standby mode until timeout expires; this would allow other threads to move forward while still maintaining balance with Thread A. If you take too long on one task then there&#8217;s no telling what might happen &#8211; you never know who needs you or where the next opportunity will arise! So always keep your eyes open and your ears peeled just in case someone needs some help or wants advice!<\/span><\/p>\n<h3><strong>5)Terminated:<\/strong><\/h3>\n<p data-slate-node=\"element\"><span data-slate-node=\"text\">A thread can terminate due to the following reasons:<\/span><\/p>\n<p data-slate-node=\"element\" data-slate-fragment=\"JTVCJTdCJTIydHlwZSUyMiUzQSUyMnBhcmFncmFwaCUyMiUyQyUyMmFsaWduJTIyJTNBJTIyJTIyJTJDJTIyY2hpbGRyZW4lMjIlM0ElNUIlN0IlMjJ0ZXh0JTIyJTNBJTIyQSUyMHRocmVhZCUyMGNhbiUyMHRlcm1pbmF0ZSUyMGR1ZSUyMHRvJTIwdGhlJTIwZm9sbG93aW5nJTIwcmVhc29ucyUzQSUyMiU3RCU1RCU3RCUyQyU3QiUyMnR5cGUlMjIlM0ElMjJwYXJhZ3JhcGglMjIlMkMlMjJhbGlnbiUyMiUzQSUyMiUyMiUyQyUyMmNoaWxkcmVuJTIyJTNBJTVCJTdCJTIydGV4dCUyMiUzQSUyMldoZW4lMjBhJTIwdGhyZWFkJTIwaGFzJTIwZmluaXNoZWQlMjBpdHMlMjBqb2IlMkMlMjB0aGVuJTIwaXQlMjBlaXRoZXIlMjBleGlzdHMlMjBvciUyMHRlcm1pbmF0ZXMlMjBub3JtYWxseS4lMjBBYm5vcm1hbCUyMHRlcm1pbmF0aW9uJTNBJTIwSXQlMjBvY2N1cnMlMjB3aGVuJTIwc29tZSUyMHVudXN1YWwlMjBldmVudHMlMjBzdWNoJTIwYXMlMjBhbiUyMHVuaGFuZGxlZCUyMGV4Y2VwdGlvbiUyMG9yJTIwc2VnbWVudGF0aW9uJTIwZmF1bHQlMjBoYXBwZW4uJTIwQSUyMHRlcm1pbmF0ZWQlMjB0aHJlYWQlMjBtZWFucyUyMHRoZSUyMHRocmVhZCUyMGlzJTIwbm8lMjBtb3JlJTIwaW4lMjB0aGUlMjBzeXN0ZW0lMjAtJTIwd2hpY2glMjBlc3NlbnRpYWxseSUyMG1lYW5zJTIwdGhhdCUyMHRoZSUyMHRocmVhZCUyMGlzJTIwZGVhZCUyMGFuZCUyMHRoZXJlJ3MlMjBub3RoaW5nJTIwd2UlMjBjYW4lMjBkbyUyMGFib3V0JTIwaXQlMjBleGNlcHQlMjBob3BlJTIwZm9yJTIwaXQlMjB0byUyMHJlc3Bhd24lMjBpZiUyMGFjdGl2ZSUyMGJlZm9yZSUyMGJlaW5nJTIwa2lsbGVkJTIwb2ZmLiUyMiU3RCU1RCU3RCU1RA==\"><span data-slate-node=\"text\">When a thread has finished its job, then it either exists or terminates normally. Abnormal termination: It occurs when some unusual events such as an unhandled exception or segmentation fault happen. A terminated thread means the thread is no more in the system &#8211; which essentially means that the thread is dead and there&#8217;s nothing we can do about it except hope for it to respawn if active before being killed off.<\/span><\/p>\n<p>\u00a0A life cycle of a thread in java is considered running if it is either on CPU or pre-empted by another thread. Once a thread has been interrupted by another thread, it becomes runnable. In many instances, threads can become blocked as they wait for data from I\/O operations like network access or disk I\/O. In these situations, they have <a href=\"https:\/\/entri.sng.link\/Bcofz\/uu8c\/w409\">no choice<\/a> but to wait until such time that there\u2019s no longer an issue with the I\/O operation and then proceed with their processing. Occasionally, threads become blocked because their task has yet to be completed. This means that once a thread has been created for performing specific tasks or purposes that it will only continue its execution once those tasks have been completed.<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/bit.ly\/3ELmCiA\">Get the latest updates on java programming in the Entri app<\/a><\/p>\n<p>The reason why this happens is that the OS allocates CPU resources to threads that are currently executing while simultaneously suspending other ones. When allocating <a href=\"https:\/\/entri.sng.link\/Bcofz\/uu8c\/w409\">CPU resources<\/a>, most operating systems use some form of the scheduling algorithm. The two primary forms of scheduling algorithms used today are preemptive and cooperative multitasking. Preemptive multitasking ensures that one process isn\u2019t allowed to monopolize CPU resources without interruption while cooperative multitasking requires one process voluntarily yields when others need more CPU cycles.<\/p>\n<h2 class=\"h2\"><span class=\"ez-toc-section\" id=\"Java_Program_for_the_Demonstrating_Thread_States\"><\/span><strong>Java Program for the Demonstrating Thread States<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The below-mentioned Java program shows some of the states of a thread defined above.<\/p>\n<p>FileName:\u00a0ThreadState.java<\/p>\n<div class=\"codeblock\">\n<div class=\"dp-highlighter\">\n<p><span class=\"comment\">\/\/\u00a0ABC\u00a0class\u00a0implements\u00a0the\u00a0interface\u00a0Runnable<\/span><\/p>\n<p><span class=\"keyword\">class<\/span>\u00a0ABC\u00a0<span class=\"keyword\">implements<\/span>\u00a0Runnable<\/p>\n<p>{<\/p>\n<p><span class=\"keyword\">public<\/span>\u00a0<span class=\"keyword\">void<\/span>\u00a0run()<\/p>\n<p>{<\/p>\n<p>&nbsp;<\/p>\n<p><span class=\"comment\">\/\/\u00a0try-catch\u00a0block<\/span><\/p>\n<p><span class=\"keyword\">try<\/span><\/p>\n<p>{<\/p>\n<p><span class=\"comment\">\/\/\u00a0moving\u00a0thread\u00a0t2\u00a0to\u00a0the\u00a0state\u00a0timed\u00a0waiting<\/span><\/p>\n<p>Thread.sleep(<span class=\"number\">100<\/span>);<\/p>\n<p>}<\/p>\n<p><span class=\"keyword\">catch<\/span>\u00a0(InterruptedException\u00a0ie)<\/p>\n<p>{<\/p>\n<p>ie.printStackTrace();<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>System.out.println(<span class=\"string\">&#8220;The\u00a0state\u00a0of\u00a0thread\u00a0t1\u00a0while\u00a0it\u00a0invoked\u00a0the\u00a0method\u00a0join()\u00a0on\u00a0thread\u00a0t2\u00a0-&#8220;<\/span>+\u00a0ThreadState.t1.getState());<\/p>\n<p>&nbsp;<\/p>\n<p><span class=\"comment\">\/\/\u00a0try-catch\u00a0block<\/span><\/p>\n<p><span class=\"keyword\">try<\/span><\/p>\n<p>{<\/p>\n<p>Thread.sleep(<span class=\"number\">200<\/span>);<\/p>\n<p>}<\/p>\n<p><span class=\"keyword\">catch<\/span>\u00a0(InterruptedException\u00a0ie)<\/p>\n<p>{<\/p>\n<p>ie.printStackTrace();<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p><span class=\"comment\">\/\/\u00a0ThreadState\u00a0class\u00a0implements\u00a0the\u00a0interface\u00a0Runnable<\/span><\/p>\n<p><span class=\"keyword\">public<\/span>\u00a0<span class=\"keyword\">class<\/span>\u00a0ThreadState\u00a0<span class=\"keyword\">implements<\/span>\u00a0Runnable<\/p>\n<p>{<\/p>\n<p><span class=\"keyword\">public<\/span>\u00a0<span class=\"keyword\">static<\/span>\u00a0Thread\u00a0t1;<\/p>\n<p><span class=\"keyword\">public<\/span>\u00a0<span class=\"keyword\">static<\/span>\u00a0ThreadState\u00a0obj;<\/p>\n<p>&nbsp;<\/p>\n<p><span class=\"comment\">\/\/\u00a0main\u00a0method\u00a0<\/span><\/p>\n<p><span class=\"keyword\">public<\/span>\u00a0<span class=\"keyword\">static<\/span>\u00a0<span class=\"keyword\">void<\/span>\u00a0main(String\u00a0argvs[])<\/p>\n<p>{<\/p>\n<p><span class=\"comment\">\/\/\u00a0creating\u00a0an\u00a0object\u00a0of\u00a0the\u00a0class\u00a0ThreadState<\/span><\/p>\n<p>obj\u00a0=\u00a0<span class=\"keyword\">new<\/span>\u00a0ThreadState();<\/p>\n<p>t1\u00a0=\u00a0<span class=\"keyword\">new<\/span>\u00a0Thread(obj);<\/p>\n<p>&nbsp;<\/p>\n<p><span class=\"comment\">\/\/\u00a0thread\u00a0t1\u00a0is\u00a0spawned\u00a0<\/span><\/p>\n<p><span class=\"comment\">\/\/\u00a0The\u00a0thread\u00a0t1\u00a0is\u00a0currently\u00a0in\u00a0the\u00a0NEW\u00a0state.<\/span><\/p>\n<p>System.out.println(<span class=\"string\">&#8220;The\u00a0state\u00a0of\u00a0thread\u00a0t1\u00a0after\u00a0spawning\u00a0it\u00a0&#8211;\u00a0&#8220;<\/span>\u00a0+\u00a0t1.getState());<\/p>\n<p>&nbsp;<\/p>\n<p><span class=\"comment\">\/\/\u00a0invoking\u00a0the\u00a0start()\u00a0method\u00a0on\u00a0<\/span><\/p>\n<p><span class=\"comment\">\/\/\u00a0the\u00a0thread\u00a0t1<\/span><\/p>\n<p>t1.start();<\/p>\n<p>&nbsp;<\/p>\n<p><span class=\"comment\">\/\/\u00a0thread\u00a0t1\u00a0is\u00a0moved\u00a0to\u00a0the\u00a0Runnable\u00a0state<\/span><\/p>\n<p>System.out.println(<span class=\"string\">&#8220;The\u00a0state\u00a0of\u00a0thread\u00a0t1\u00a0after\u00a0invoking\u00a0the\u00a0method\u00a0start()\u00a0on\u00a0it\u00a0&#8211;\u00a0&#8220;<\/span>\u00a0+\u00a0t1.getState());<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p><span class=\"keyword\">public<\/span>\u00a0<span class=\"keyword\">void<\/span>\u00a0run()<\/p>\n<p>{<\/p>\n<p>ABC\u00a0myObj\u00a0=\u00a0<span class=\"keyword\">new<\/span>\u00a0ABC();<\/p>\n<p>Thread\u00a0t2\u00a0=\u00a0<span class=\"keyword\">new<\/span>\u00a0Thread(myObj);<\/p>\n<p>&nbsp;<\/p>\n<p><span class=\"comment\">\/\/\u00a0thread\u00a0t2\u00a0is\u00a0created\u00a0and\u00a0is\u00a0currently\u00a0in\u00a0the\u00a0NEW\u00a0state.<\/span><\/p>\n<p>System.out.println(<span class=\"string\">&#8220;The\u00a0state\u00a0of\u00a0thread\u00a0t2\u00a0after\u00a0spawning\u00a0it\u00a0&#8211;\u00a0&#8220;<\/span>+\u00a0t2.getState());<\/p>\n<p>t2.start();<\/p>\n<p>&nbsp;<\/p>\n<p><span class=\"comment\">\/\/\u00a0thread\u00a0t2\u00a0is\u00a0moved\u00a0to\u00a0the\u00a0runnable\u00a0state<\/span><\/p>\n<p>System.out.println(<span class=\"string\">&#8220;the\u00a0state\u00a0of\u00a0thread\u00a0t2\u00a0after\u00a0calling\u00a0the\u00a0method\u00a0start()\u00a0on\u00a0it\u00a0&#8211;\u00a0&#8220;<\/span>\u00a0+\u00a0t2.getState());<\/p>\n<p>&nbsp;<\/p>\n<p><span class=\"comment\">\/\/\u00a0try-catch\u00a0block\u00a0for\u00a0the\u00a0smooth\u00a0flow\u00a0of\u00a0the\u00a0\u00a0program<\/span><\/p>\n<p><span class=\"keyword\">try<\/span><\/p>\n<p>{<\/p>\n<p><span class=\"comment\">\/\/\u00a0moving\u00a0the\u00a0thread\u00a0t1\u00a0to\u00a0the\u00a0state\u00a0timed\u00a0waiting\u00a0<\/span><\/p>\n<p>Thread.sleep(<span class=\"number\">200<\/span>);<\/p>\n<p>}<\/p>\n<p><span class=\"keyword\">catch<\/span>\u00a0(InterruptedException\u00a0ie)<\/p>\n<p>{<\/p>\n<p>ie.printStackTrace();<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>System.out.println(<span class=\"string\">&#8220;The\u00a0state\u00a0of\u00a0thread\u00a0t2\u00a0after\u00a0invoking\u00a0the\u00a0method\u00a0sleep()\u00a0on\u00a0it\u00a0&#8211;\u00a0&#8220;<\/span>+\u00a0t2.getState()\u00a0);<\/p>\n<p>&nbsp;<\/p>\n<p><span class=\"comment\">\/\/\u00a0try-catch\u00a0block\u00a0for\u00a0the\u00a0smooth\u00a0flow\u00a0of\u00a0the\u00a0\u00a0program<\/span><\/p>\n<p><span class=\"keyword\">try<\/span><\/p>\n<p>{<\/p>\n<p><span class=\"comment\">\/\/\u00a0waiting\u00a0for\u00a0thread\u00a0t2\u00a0to\u00a0complete\u00a0its\u00a0execution<\/span><\/p>\n<p>t2.join();<\/p>\n<p>}<\/p>\n<p><span class=\"keyword\">catch<\/span>\u00a0(InterruptedException\u00a0ie)<\/p>\n<p>{<\/p>\n<p>ie.printStackTrace();<\/p>\n<p>}<\/p>\n<p>System.out.println(<span class=\"string\">&#8220;The\u00a0state\u00a0of\u00a0thread\u00a0t2\u00a0when\u00a0it\u00a0has\u00a0completed\u00a0it&#8217;s\u00a0execution\u00a0&#8211;\u00a0&#8220;<\/span>\u00a0+\u00a0t2.getState());<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>}<\/p>\n<\/div>\n<\/div>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"codeblock3\">\n<pre>The state of thread t1 after spawning it - NEW\r\nThe state of thread t1 after invoking the method start() on it - RUNNABLE\r\nThe state of thread t2 after spawning it - NEW\r\nthe state of thread t2 after calling the method start() on it - RUNNABLE\r\nThe state of thread t1 while it invoked the method join() on thread t2 -TIMED_WAITING\r\nThe state of thread t2 after invoking the method sleep() on it - TIMED_WAITING\r\nThe state of thread t2 when it has completed it's execution - TERMINATED<\/pre>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span><strong>Conclusion<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>In reality, it may be hard to keep all these steps in mind when you\u2019re coding. I usually try to write a small test case and just practice writing some different examples. There are many good sources that dive into each step much deeper (such as below), but without first working with these examples, it might be too abstract to understand what\u2019s going on. The key is being able to see an example run and then using that as inspiration for your own code. Eventually, you\u2019ll get used to thinking <a href=\"https:\/\/entri.sng.link\/Bcofz\/uu8c\/w409\">about threads<\/a> and concurrency issues and will start noticing when there might be an issue with your code or design. If you are interested to learn new coding skills, the Entri app will help you to acquire them very easily. Entri app is following a structural study plan so that the students can learn very easily. If you don&#8217;t have a coding background, it won&#8217;t be a problem. You can download the Entri app from the google play store and enroll in your favorite course.<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/bit.ly\/3ELmCiA\">Enroll in our latest java programming course in the Entri app<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java threads run on the JVM (Java Virtual Machine). A thread methods in java is an execution context that can simultaneously execute different tasks, but only one task at a time. While the GIL (Global Interpreter Lock) ensures that only one thread runs at a time, threads still perform better than processes with real parallelism [&hellip;]<\/p>\n","protected":false},"author":93,"featured_media":25531494,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[802,1864,1882,1883,1881],"tags":[],"class_list":["post-25531490","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-articles","category-data-science-ml","category-java-programming","category-react-native","category-web-android-development"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Life Cycle of a Thread in Java: An Overview - Entri Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Life Cycle of a Thread in Java: An Overview - Entri Blog\" \/>\n<meta property=\"og:description\" content=\"Java threads run on the JVM (Java Virtual Machine). A thread methods in java is an execution context that can simultaneously execute different tasks, but only one task at a time. While the GIL (Global Interpreter Lock) ensures that only one thread runs at a time, threads still perform better than processes with real parallelism [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/\" \/>\n<meta property=\"og:site_name\" content=\"Entri Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/entri.me\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-07-01T14:30:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-19T11:36:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Untitled-84-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"820\" \/>\n\t<meta property=\"og:image:height\" content=\"615\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Akhil M G\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@entri_app\" \/>\n<meta name=\"twitter:site\" content=\"@entri_app\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Akhil M G\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/\"},\"author\":{\"name\":\"Akhil M G\",\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/person\/875646423b2cce93c1bd5bc16850fff6\"},\"headline\":\"Life Cycle of a Thread in Java: An Overview\",\"datePublished\":\"2022-07-01T14:30:03+00:00\",\"dateModified\":\"2022-11-19T11:36:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/\"},\"wordCount\":1833,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/entri.app\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Untitled-84-1.png\",\"articleSection\":[\"Articles\",\"Data Science and Machine Learning\",\"Java Programming\",\"React Native\",\"Web and Android Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/\",\"url\":\"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/\",\"name\":\"Life Cycle of a Thread in Java: An Overview - Entri Blog\",\"isPartOf\":{\"@id\":\"https:\/\/entri.app\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Untitled-84-1.png\",\"datePublished\":\"2022-07-01T14:30:03+00:00\",\"dateModified\":\"2022-11-19T11:36:03+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/#primaryimage\",\"url\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Untitled-84-1.png\",\"contentUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Untitled-84-1.png\",\"width\":820,\"height\":615,\"caption\":\"Life Cycle of a Thread in Java: An Overview\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/entri.app\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Entri Skilling\",\"item\":\"https:\/\/entri.app\/blog\/category\/entri-skilling\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Java Programming\",\"item\":\"https:\/\/entri.app\/blog\/category\/entri-skilling\/java-programming\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Life Cycle of a Thread in Java: An Overview\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/entri.app\/blog\/#website\",\"url\":\"https:\/\/entri.app\/blog\/\",\"name\":\"Entri Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/entri.app\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/entri.app\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/entri.app\/blog\/#organization\",\"name\":\"Entri App\",\"url\":\"https:\/\/entri.app\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png\",\"contentUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png\",\"width\":989,\"height\":446,\"caption\":\"Entri App\"},\"image\":{\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/entri.me\/\",\"https:\/\/x.com\/entri_app\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/person\/875646423b2cce93c1bd5bc16850fff6\",\"name\":\"Akhil M G\",\"url\":\"https:\/\/entri.app\/blog\/author\/akhil\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Life Cycle of a Thread in Java: An Overview - Entri Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/","og_locale":"en_US","og_type":"article","og_title":"Life Cycle of a Thread in Java: An Overview - Entri Blog","og_description":"Java threads run on the JVM (Java Virtual Machine). A thread methods in java is an execution context that can simultaneously execute different tasks, but only one task at a time. While the GIL (Global Interpreter Lock) ensures that only one thread runs at a time, threads still perform better than processes with real parallelism [&hellip;]","og_url":"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/","og_site_name":"Entri Blog","article_publisher":"https:\/\/www.facebook.com\/entri.me\/","article_published_time":"2022-07-01T14:30:03+00:00","article_modified_time":"2022-11-19T11:36:03+00:00","og_image":[{"width":820,"height":615,"url":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Untitled-84-1.png","type":"image\/png"}],"author":"Akhil M G","twitter_card":"summary_large_image","twitter_creator":"@entri_app","twitter_site":"@entri_app","twitter_misc":{"Written by":"Akhil M G","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/#article","isPartOf":{"@id":"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/"},"author":{"name":"Akhil M G","@id":"https:\/\/entri.app\/blog\/#\/schema\/person\/875646423b2cce93c1bd5bc16850fff6"},"headline":"Life Cycle of a Thread in Java: An Overview","datePublished":"2022-07-01T14:30:03+00:00","dateModified":"2022-11-19T11:36:03+00:00","mainEntityOfPage":{"@id":"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/"},"wordCount":1833,"commentCount":0,"publisher":{"@id":"https:\/\/entri.app\/blog\/#organization"},"image":{"@id":"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/#primaryimage"},"thumbnailUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Untitled-84-1.png","articleSection":["Articles","Data Science and Machine Learning","Java Programming","React Native","Web and Android Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/","url":"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/","name":"Life Cycle of a Thread in Java: An Overview - Entri Blog","isPartOf":{"@id":"https:\/\/entri.app\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/#primaryimage"},"image":{"@id":"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/#primaryimage"},"thumbnailUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Untitled-84-1.png","datePublished":"2022-07-01T14:30:03+00:00","dateModified":"2022-11-19T11:36:03+00:00","breadcrumb":{"@id":"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/#primaryimage","url":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Untitled-84-1.png","contentUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Untitled-84-1.png","width":820,"height":615,"caption":"Life Cycle of a Thread in Java: An Overview"},{"@type":"BreadcrumbList","@id":"https:\/\/entri.app\/blog\/life-cycle-of-a-thread-in-java-an-overview\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/entri.app\/blog\/"},{"@type":"ListItem","position":2,"name":"Entri Skilling","item":"https:\/\/entri.app\/blog\/category\/entri-skilling\/"},{"@type":"ListItem","position":3,"name":"Java Programming","item":"https:\/\/entri.app\/blog\/category\/entri-skilling\/java-programming\/"},{"@type":"ListItem","position":4,"name":"Life Cycle of a Thread in Java: An Overview"}]},{"@type":"WebSite","@id":"https:\/\/entri.app\/blog\/#website","url":"https:\/\/entri.app\/blog\/","name":"Entri Blog","description":"","publisher":{"@id":"https:\/\/entri.app\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/entri.app\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/entri.app\/blog\/#organization","name":"Entri App","url":"https:\/\/entri.app\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png","contentUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png","width":989,"height":446,"caption":"Entri App"},"image":{"@id":"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/entri.me\/","https:\/\/x.com\/entri_app"]},{"@type":"Person","@id":"https:\/\/entri.app\/blog\/#\/schema\/person\/875646423b2cce93c1bd5bc16850fff6","name":"Akhil M G","url":"https:\/\/entri.app\/blog\/author\/akhil\/"}]}},"_links":{"self":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts\/25531490","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/users\/93"}],"replies":[{"embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/comments?post=25531490"}],"version-history":[{"count":5,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts\/25531490\/revisions"}],"predecessor-version":[{"id":25547421,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts\/25531490\/revisions\/25547421"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/media\/25531494"}],"wp:attachment":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/media?parent=25531490"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/categories?post=25531490"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/tags?post=25531490"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}