�Another reason to use the Runnable interface is that you may need to run an object multiple times�However, you can create as many threads as you want by using a Runnable instance.�
From Mike Meyers� certification Passport-Java 2
Let us be showered in the light of confusion!
Amir
Francisco<br />SCJP<br />please use the [code][/code] tags when showing code.Click <a href="http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=ubb_code_page" target="_blank">here</a> to see an example.
Originally posted by Francisco A Guimaraes:
When you extend Thread, each instance you create is like creating a new "processor" only for that thread. In the other hand, when you implement the Runnable interface it�s like you�re using one "processor" for all your threads. That�s the explanation I remember from the R&H book. Anyone correct me if i�m wrong.
Hope that helps,
Francisco
Let us be showered in the light of confusion!
When you extend Thread, each instance you create is like creating a new "processor" only for that thread. In the other hand, when you implement the Runnable interface it�s like you�re using one "processor" for all your threads.
Let us be showered in the light of confusion!
After I run the program, it seems to me that If I use Runnable as a target for threads, what I have are multiple threads that can use the same object, namely whatever I got that implements Runnable, thus the deal with running one object multiple time. With Thread, I'll get multiple threads each running its own copy the object.
Is that about right?
Thanks in advance, I have trouble on the finer details of threads...
Originally posted by Chung Huang:
After I run the program, it seems to me that If I use Runnable as a target for threads, what I have are multiple threads that can use the same object, namely whatever I got that implements Runnable, thus the deal with running one object multiple time. With Thread, I'll get multiple threads each running its own copy the object.
Is that about right?
new Thread((Runnable)mt).start();
new Thread((Runnable)mt).start();
Originally posted by Anthony Villanueva:
OR, class X implements Runnable, implements run() and calls Thread(Runnable r), in which case each X object is being accessed by (possibly) multiple threads.