aspose file tools*
The moose likes Threads and Synchronization and the fly likes Thread Quetion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Thread Quetion" Watch "Thread Quetion" New topic
Author

Thread Quetion

Venkatachalam Palanisamy
Greenhorn

Joined: Aug 04, 2000
Posts: 12
Dear All,
class Thre extends Thread
{
public void run()
{
System.out.println("Running........");
}
public void run(int j)
{
System.out.println("Yes----> "+j);
}
public static void main(String[] args)
{
Thre t = new Thre();
t.start();
t.run(200);
}
}
why the output of the above code snippet is
Yes -----> 200
Running........
i expected the output in the reverse order..
can any one give me the explanation or relavent URL.
Thanks & Regards,
Venkatachalam VP
David Weitzman
Ranch Hand

Joined: Jul 27, 2001
Posts: 1365
When you call run(int), it executes immediately. When you call start(), you have scheduled the run() method for asynchronous execution -- it could very well finish executing before the call to run(int), but because of all the overhead of switching threads and whatnot it probably won't.
Thomas Markl
Ranch Hand

Joined: Mar 08, 2001
Posts: 192
Hello,
I just transferred the program from "extends Thread" to "implements Runnable".
class Thre1 implements Runnable {
public void run() {
System.out.println("Running........");
}
public void run(int j) {
System.out.println("Yes----> "+j);
}
public static void main(String[] args) {
Thre1 thre1 = new Thre1();
Thread t = new Thread(thre1);
t.start();
// t.run(200) is not possible because t is Thread
// object and Thread class has only run() method
// and not run(int j) method!!
thre1.run(200);
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread Quetion