The Runnable interface defines an abstract run() method and the Thread class implements the interface, so has its own concrete run() method. However the Thread class implementation of run() is different from most others because of its special use in the creation of new threads.
The Thread run() method has no “worker” code of its own, it just calls the run() method of the Runnable object that was passed to its constructor.
To instantiate a Thread object we normally pass a Runnable class to the constructor as the “target” of the thread. When you call the Thread's start() method it creates a new thread whose first and only action is the to call Thread class' own run() method once. The Thread class run() calls the run() method on the target Runnable, which does the work of the thread.
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Abimaran Kugathasan wrote:Check this code....
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ankit Garg wrote:Did you start the thread??
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Abimaran Kugathasan wrote:
Ankit Garg wrote:Did you start the thread??
I forgot..................................
Thanks Ankit.....
M.Sc. in CS, OCPJP6 93%
Unmesh Chowdhury wrote:Hi Mr. Ankit Grag,
You have discussed the internal chaining of starting of a thread of execution when we create a thread from a Runnable object. But what will be the internal chaining of starting of a thread of execution when we create a thread by extending it from the java.lang.Thread class, for instance:
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Unmesh Chowdhury wrote:You have discussed the internal chaining of starting of a thread of execution when we create a thread from a Runnable object. But what will be the internal chaining of starting of a thread of execution when we create a thread by extending it from the java.lang.Thread class
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
M.Sc. in CS, OCPJP6 93%
Unmesh Chowdhury wrote:automatic internal chaining is comes into play if we create our thread object directly from the java.lang.Thread class.
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
M.Sc. in CS, OCPJP6 93%
I do some of my very best work in water. Like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|