aspose file tools*
The moose likes Java in General and the fly likes Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Threads" Watch "Threads" New topic
Author

Threads

Kristof Camelbeke
Ranch Hand

Joined: Nov 28, 2001
Posts: 97
I have a question concerning the method start().... I have seen an example class which extends from Thread and overrides the run() method of Thread. But I have read that in order to start a thread you should invoke the start method on the instance of the subclass, is this correct ? Because in this example the start method is never invoked ; does this mean that the overriden run() is never executed ???
Kamlesh Sangani
Greenhorn

Joined: Feb 28, 2004
Posts: 22
ya, start() internally calls run(). u need not call run().


Lets Java !<br />Kamlesh
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12823
    
    5
NO - start does NOT "call run" - start puts the Thread in a runnable state so the JVM will schedule it to execute the run method. You have to call the start() method of the Thread or the class that extends Thread.
While you can have another Thread call the run method, that defeats the whole idea. The JavaDocs for the java.lang.Thread class are very clear on this - I heartily recommend that you read them.
Bill
Nick Way
Greenhorn

Joined: Feb 06, 2004
Posts: 7
The other way is to have your class implement Runnable, then you can start a thread as follows:
new Thread(new YourClass()).start();
That will call the run() method in your class.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Threads