Why is run() not immediately called when start() called on a thread object in java
Posted
by pi
on Stack Overflow
See other posts from Stack Overflow
or by pi
Published on 2010-04-22T11:10:25Z
Indexed on
2010/04/22
11:13 UTC
Read the original article
Hit count: 244
Or is it?
I have a thread object from:
Thread myThread = new Thread(pObject);
Where pObject is an object of a class implementing the Runnable interface and then I have the start method called on the thread object like so:
myThread.start();
Now, my understanding is that when start() is called, the JVM implicitly (and immediately) calls the run() method which may be overridden (as it is in my case)
However, in my case, it appears that the start() method is not called immediately (as desired) but until the other statements/methods are completed from the calling block i.e. if I had a method after the start() call like so:
myThread.start();
doSomethingElse();
doSomthingElse() gets executed before the run() method is run at all.
Perhaps I am wrong with the initial premise that run() is always called right after the start() is called. Please help! The desired again is making executing run() right after start(). Thanks.
© Stack Overflow or respective owner