KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
public class CreateThreadRunnableExample implements Runnable { public void run() { for (int i = 0; i < 5; i++) { System.out.println("Child Thread : " + i); try { Thread.sleep(50); } catch (InterruptedException ie) { System.out.println("Child thread interrupted! " + ie); } } System.out.println("Child thread finished!"); } public static void main(String[] args) { Thread t = new Thread(new CreateThreadRunnableExample(), "My Thread"); t.start(); for (int i = 0; i < 5; i++) { System.out.println("Main thread : " + i); try { Thread.sleep(100); } catch (InterruptedException ie) { System.out.println("Child thread interrupted! " + ie); } } System.out.println("Main thread finished!"); } } in this program two sleep methods are used of deifferent time..,,, so if main thread run time then child thread have to run 2 time.but it runs one time only....it we take the concept of runnable or running state....then when main thread end,then 2 child threads will be in ready state then why only one child thread runs.
Tags (comma-separated)
Save Edits
Cancel