Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


cant we call run() method directly instead of calling indirectly through the start()
method ? if we do so then what is the problem ?

Answers were Sorted based on User's Feedback



cant we call run() method directly instead of calling indirectly through the start() method ? if w..

Answer / will

Calling run() without calling start() will effectively
execute run() in the current thread.

Calling start() will kick off a seperate thread,from your
current thread, which will then call run().

Is This Answer Correct ?    12 Yes 4 No

cant we call run() method directly instead of calling indirectly through the start() method ? if w..

Answer / srinu

Calling run() without calling start() will effectively
execute run() in the current thread.then that time only one
thread it will be created.but n't achiving the mulithreading
concepts.

ex:-
class Sample extends Thread
{
Sample()
{
System.out.println("hai how are u");
}
public void run()
{
System.out.println("run method will be called");
}
}

public class ThreadExample
{
public static void main(String k[])
{
Sample s=new Sample();
s.run();
int k1=Sample.activeCount();

System.out.println(k1);
}
}

OUTPUT:
hai how are u
run method will be called
1
IN this program only one thread will be created.

start()--->
Calling start() will kick off a seperate thread,from your
current thread, which will then call run().

EX:-
class Sample extends Thread
{
Sample()
{
System.out.println("hai how are u");
}
public void run()
{
System.out.println("run method will be called");
}
}

public class ThreadExample
{
public static void main(String k[])
{
Sample s=new Sample();
s.start();
int k1=Sample.activeCount();

System.out.println(k1);
}
}
OUTPUT:
hai how are u
run method will be called
2
In this program 2 threads will be started.

Is This Answer Correct ?    7 Yes 2 No

cant we call run() method directly instead of calling indirectly through the start() method ? if w..

Answer / dara

Calling run() without calling start() will effectively
execute run() is a normal method.

Calling start() will kick off a separate thread,from your
current thread, which will then call run().

Is This Answer Correct ?    5 Yes 0 No

cant we call run() method directly instead of calling indirectly through the start() method ? if w..

Answer / neeraj_passion2001

yes you can call run() as ordinary method.
but while calling run() explicitly u can not achieve multi
threading.

Is This Answer Correct ?    8 Yes 5 No

cant we call run() method directly instead of calling indirectly through the start() method ? if w..

Answer / damodar narayan

Calling run() method is just like calling a method in java. So when called, it just gets executed but "we do not get the thread functionality by calling the run() method". But calling start() method registers your program with the thread scheduler and hence it achieves the threading functionality. Start in turn calls the runs method.

Hope its clear.

Is This Answer Correct ?    3 Yes 0 No

cant we call run() method directly instead of calling indirectly through the start() method ? if w..

Answer / xyz

can we call start () inside run() of a thread

Is This Answer Correct ?    3 Yes 1 No

cant we call run() method directly instead of calling indirectly through the start() method ? if w..

Answer / rajkiran bande

@Answer 5 : Yes. But you'll eventually end up in getting
IllegealThreadStateException when run() is invoked for the
second time.

Is This Answer Correct ?    2 Yes 0 No

Post New Answer

More Java Related AllOther Interview Questions

What is the difference between jar and executable jar?

0 Answers  


Why doesn’t the main method throw an error with no arguments?

0 Answers  


In java what is the difference between sleep() and wait() .

0 Answers   Amazon,


how we can export all the contacts and messages from nokia mobile to other mobile or pc? (pls answer quickly)

1 Answers  


I run a web server. Am I at risk? : java security

0 Answers  


Why bean class is used in java?

0 Answers  


What are orm tools in java?

0 Answers  


suppose we have one String s="india is my country"; now we get the o/p "like country my is India". what is the logic?

2 Answers  


How do I enable java in google chrome?

0 Answers  


Who developed JavaScript, and what was the first name of JavaScript?

1 Answers  


Is openjdk the same as jdk?

0 Answers  


How does java handle integer overflows and underflows?

0 Answers  


Categories