{"id":1319,"date":"2016-04-27T09:40:09","date_gmt":"2016-04-27T09:40:09","guid":{"rendered":"http:\/\/abhiandroid.com\/java\/?p=1319"},"modified":"2018-06-05T06:13:02","modified_gmt":"2018-06-05T06:13:02","slug":"lifecycle-of-thread","status":"publish","type":"post","link":"https:\/\/abhiandroid.com\/java\/lifecycle-of-thread.html","title":{"rendered":"Life Cycle of a Thread In JAVA"},"content":{"rendered":"<p>In Multithreading, Thread can be in one of the five states which forms life cycle of the Thread. This life cycle of a thread is controlled by java virtual machine (JVM).<\/p>\n<p>Following are the five stages by which Thread goes through in its lifecycle as shown in figure 1.1 :<\/p>\n<ol>\n<li>New<\/li>\n<li>Runnable<\/li>\n<li>Running<\/li>\n<li>Non-Runnable (Blocked)<\/li>\n<li>Terminated<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p><a href=\"\/java\/wp-content\/uploads\/2016\/04\/LifeCycleOfThread-1.png\" rel=\"attachment wp-att-1327\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1327\" src=\"\/java\/wp-content\/uploads\/2016\/04\/LifeCycleOfThread-1.png\" alt=\"LifeCycleOfThread\" width=\"514\" height=\"331\" srcset=\"https:\/\/abhiandroid.com\/java\/wp-content\/uploads\/2016\/04\/LifeCycleOfThread-1.png 810w, https:\/\/abhiandroid.com\/java\/wp-content\/uploads\/2016\/04\/LifeCycleOfThread-1-300x193.png 300w, https:\/\/abhiandroid.com\/java\/wp-content\/uploads\/2016\/04\/LifeCycleOfThread-1-768x494.png 768w\" sizes=\"auto, (max-width: 514px) 100vw, 514px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Let us discuss each Stage in Detail One by one:<\/strong><\/p>\n<p><span style=\"color: #008000;\"><strong>1. New<\/strong><\/span><\/p>\n<p>In this stage thread is referred to as a born thread. A new thread starts its life cycle in this stage. The thread remains in this thread until programs starts the thread.<\/p>\n<p><span style=\"color: #008000;\"><strong>2. Runnable<\/strong><\/span><\/p>\n<p>After a newly born thread is started , the thread comes in this stage which is referred to as runnable. The thread comes into this stage after calling start() method, Thread scheduler sets it to be runnable.<\/p>\n<p><span style=\"color: #008000;\"><strong>3. Running<\/strong><\/span><\/p>\n<p>Thread is in running stage only when Thread Scheduler has selected it. It executes all the tasks assigned to it in this stage.<\/p>\n<p><span style=\"color: #008000;\"><strong>4. Non-Runnable (Blocked)<\/strong><\/span><\/p>\n<p>In this stage, Thread is still alive but it is not eligible to run due to some condition. In this stage thread is referred to be in waiting stage.<\/p>\n<p><span style=\"color: #008000;\"><strong>5. Terminated<\/strong><\/span><\/p>\n<p>Thread is terminated when its run() method exists. In this stage thread is referred as Dead thread.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Multithreading, Thread can be in one of the five states which forms life cycle of the Thread. This life cycle of a thread is controlled by java virtual machine (JVM). Following are the five stages by which Thread goes through in its lifecycle as shown in figure 1.1 : New Runnable Running Non-Runnable (Blocked) &hellip; <a href=\"https:\/\/abhiandroid.com\/java\/lifecycle-of-thread.html\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Life Cycle of a Thread In JAVA<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,81],"tags":[],"class_list":["post-1319","post","type-post","status-publish","format-standard","hentry","category-archieve","category-thread"],"psp_head":"<title>Life Cycle of a Thread In JAVA \u2013 Abhi Android<\/title>\r\n<meta name=\"description\" content=\"In Multithreading, Thread can be in one of the five states which forms life cycle of the Thread. This life cycle of a thread is controlled by java virtual machine (JVM).\" \/>\r\n<meta name=\"robots\" content=\"index,follow\" \/>\r\n<link rel=\"canonical\" href=\"https:\/\/abhiandroid.com\/java\/lifecycle-of-thread.html\" \/>\r\n","_links":{"self":[{"href":"https:\/\/abhiandroid.com\/java\/wp-json\/wp\/v2\/posts\/1319","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/abhiandroid.com\/java\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/abhiandroid.com\/java\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/abhiandroid.com\/java\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/abhiandroid.com\/java\/wp-json\/wp\/v2\/comments?post=1319"}],"version-history":[{"count":2,"href":"https:\/\/abhiandroid.com\/java\/wp-json\/wp\/v2\/posts\/1319\/revisions"}],"predecessor-version":[{"id":1453,"href":"https:\/\/abhiandroid.com\/java\/wp-json\/wp\/v2\/posts\/1319\/revisions\/1453"}],"wp:attachment":[{"href":"https:\/\/abhiandroid.com\/java\/wp-json\/wp\/v2\/media?parent=1319"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/abhiandroid.com\/java\/wp-json\/wp\/v2\/categories?post=1319"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/abhiandroid.com\/java\/wp-json\/wp\/v2\/tags?post=1319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}