{"id":2704,"date":"2017-11-27T07:36:44","date_gmt":"2017-11-27T07:36:44","guid":{"rendered":"http:\/\/webartdevelopers.com\/?p=2704"},"modified":"2017-11-27T07:36:44","modified_gmt":"2017-11-27T07:36:44","slug":"how-to-use-is-alive-and-join-methods-in-multiple-threads-in-core-java","status":"publish","type":"post","link":"https:\/\/webartdevelopers.com\/blog\/how-to-use-is-alive-and-join-methods-in-multiple-threads-in-core-java\/","title":{"rendered":"How to use is Alive() and join() methods in Multiple Threads in Core Java"},"content":{"rendered":"<p>In this tutorial how use is Alive() and join() methods in Multiple Threads in Core Java\u00a0 is shown.<\/p>\n<p>Code:<\/p>\n<p>Thread4.java<\/p>\n<p>class MyThreads extends Thread<br \/>\n{<br \/>\nMyThreads(String name)<br \/>\n{<br \/>\nsetName(name);<br \/>\n}<\/p>\n<p>public void run()<br \/>\n{<br \/>\ntry<br \/>\n{<br \/>\nfor(int i=0;i&lt;10;i++)<br \/>\n{<br \/>\nThread.sleep(2000);<br \/>\nSystem.out.print(&#8221; &#8220;+getName()+&#8221; &#8220;+String.valueOf(i));<br \/>\n}<br \/>\n}<br \/>\ncatch(InterruptedException ie)<br \/>\n{<br \/>\nie.printStackTrace();<br \/>\n}<br \/>\n}<br \/>\n}<\/p>\n<p>class ThreadDemo<br \/>\n{<br \/>\npublic static void main(String args[])<br \/>\n{<br \/>\nMyThreads t1 = new MyThreads(&#8220;T1&#8221;);<br \/>\nMyThreads t2 = new MyThreads(&#8220;T2&#8221;);<\/p>\n<p>t1.start();<br \/>\ntry<br \/>\n{<br \/>\nif(t1.isAlive())<br \/>\n{<br \/>\nt1.join();<br \/>\n}<br \/>\n}<br \/>\ncatch(InterruptedException ie)<br \/>\n{<br \/>\nSystem.out.println(&#8220;Thread was interrupted&#8221;);<br \/>\n}<br \/>\nt2.start();<br \/>\n}<br \/>\n}<\/p>\n<p><a href=\"https:\/\/youtu.be\/TOkIO1ThqX4\">https:\/\/youtu.be\/TOkIO1ThqX4<\/a><\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"In this tutorial how use is Alive() and join() methods in Multiple Threads in Core Java\u00a0 is shown. Code: Thread4.java class MyThreads extends Thread { MyThreads(String name) { setName(name); } public void run() { try { for(int i=0;i&lt;10;i++) { Thread.sleep(2000); System.out.print(&#8221; &#8220;+getName()+&#8221; &#8220;+String.valueOf(i)); } } catch(InterruptedException ie) { ie.printStackTrace(); } } } class ThreadDemo { public static void main(String args) { MyThreads t1 = new MyThreads(&#8220;T1&#8221;); MyThreads t2 = new MyThreads(&#8220;T2&#8221;); t1.start(); try { if(t1.isAlive()) { t1.join(); } } catch(InterruptedException ie) { System.out.println(&#8220;Thread was interrupted&#8221;); } t2.start(); } }<!-- AddThis Advanced Settings generic via filter on get_the_excerpt -->","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[156],"tags":[157,191,192,190,187],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/posts\/2704"}],"collection":[{"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/comments?post=2704"}],"version-history":[{"count":2,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/posts\/2704\/revisions"}],"predecessor-version":[{"id":2706,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/posts\/2704\/revisions\/2706"}],"wp:attachment":[{"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/media?parent=2704"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/categories?post=2704"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/tags?post=2704"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}