Forums Register Login

can i invoke run method directly

+Pie Number of slices to send: Send
I have piece of code

Thread myThread= new Thread();
myThread.run();


why should be invoke start method before invoking run ? Any reason for this?
+Pie Number of slices to send: Send
Yes. Calling run does not actually start a new thread - it executes the code within the current thread context (and thus blocks it until run finishes).

Only calling start will actually start a new thread, and execute its runs method in a new concurrent context (and thus ensure that the current thread can continue running right away).
+Pie Number of slices to send: Send
[pandu ranga:]why should be invoke start method before invoking run

Start actualy calls the run method, which may or may not do some good on a single processor machine. On a multiple processor machine using the start() form allows multiple processors to work concurrently. Java has an api for this work: JDK 5.0 Concurrency-related APIs & Developer Guides -- from Sun ...
+Pie Number of slices to send: Send
 

Start actualy calls the run method, which may or may not do some good on a single processor machine.



The start() starts a thread which in turn, calls the run() method -- it doesn't directly call the run() method.

In most cases, it does "do some good" on a single processor machine. Threads are timesliced even with a single processor, so while it doesn't actually run parallel on a single processor, the asynchronous nature of threads has tons of value.

Henry
+Pie Number of slices to send: Send
Agreed, I was trying to simplifiy for poster.
I didn't like the taste of tongue and it didn't like the taste of me. I will now try this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2570 times.
Similar Threads
Overloading Thread.run( )
Dan's thread question!!
extends Thread.........
Threads !
Why this does not fail?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 10:35:48.