Multithreading :

Multithreading :

Postby Rajeev » Tue Jul 09, 2013 1:40 am

Question in multithreading:
In the below example, Is it true that, when i run thread class NameThread, only the run method in object NameRunnable will be executed.

The main() menthof of object NameRunnable will not execute ?
So thread call only invokes the run method of the runnable class and no other method ?

Please clarify/confirm ? Thanks.


class NameRunnable implements Runnable {

public void run() {

System.out.println("NameRunnable running");

System.out.println("Run by " + Thread.currentThread().getName());

}

public static void main (String [] args) {

System.out.println("thread is " + Thread.currentThread().getName());

}

public class NameThread {

public static void main (String [] args) {

NameRunnable nr = new NameRunnable();

Thread t = new Thread(nr);

t.setName("Fred");

t.start();
}
}

Regards,

Rajeev
Rajeev
 
Posts: 1
Joined: Mon Jul 08, 2013 8:15 pm

Return to Core Java

Who is online

Users browsing this forum: No registered users and 1 guest

cron