public class Question17 { public static void main(String[] args) throws Exception{ final int a=3; final int b=4;
Thread t1 = new Thread(getRunnable(a)); Thread t2 = new Thread(getRunnable(b)); t1.join(); System.out.println("End"); } public static Runnable getRunnable(final int id){ return new Runnable(){ public void run(){ for(int i=0;i<id;i++){ System.out.print(" "+i); } } }; } } The running result is "end", the thread doesnot start, why?
Jamal Hasanov
Ranch Hand
Joined: Jan 08, 2002
Posts: 411
posted
0
Hi, Weilliu You had to call start() method for thread running. *************************************** Thread t1 = new Thread(getRunnable(a)); Thread t2 = new Thread(getRunnable(b)); t1.start(); t2.start(); t1.join(); System.out.println("End"); *************************************** Jamal Hasanov www.j-think.com
Thiru Thangavelu
Ranch Hand
Joined: Aug 29, 2001
Posts: 219
posted
0
What do we actually doing here in this Runnable object?
Thanks,<br />Thiru<br />[SCJP,SCWCD,SCBCD]
Paul Villangca
Ranch Hand
Joined: Jun 04, 2002
Posts: 133
posted
0
In the problem, the start() method of both threads doesn't actually get called, so the threads don't get to run at all. The method join() doesn't do anything 'coz thread t1 isn't running.