I'm studying the Thread area for the SCJP 6.0 exam and got a question that what is the difference between run() and start() of a thread instance? Are the both ways getting a new stack of thread ? For start(), what I understand is, the thread becomes runnable state, but how is run() ? Is it running directly on top of main thread like calling a method of its own or creating a new stack ?
Both gave me nothing wrong and I just wanna check how it's different. But when I changed the style (implements Runnable), the class cannot invoke start() (this is understandable) but still can invoke run(). Does it make a new stack of thread or on top of the main thread ?
When you call run() on a Thread reference, the run() method will run in the same thread. The start() method creates a new thread (not an instance of the class but the actual concurrent thing), and the run() method will be run in that new thread.
As for the run() method: by default it calls the run() method of the runnable provided in the constructor. If none was passed it will do nothing. Of course, if you override it (like you did) you can do anything you want.