The run
method is just another method. If you call it directly, then it will execute not in another thread, but in the current thread.
Here's my test TestRunnable
:
class TestRunnable implements Runnable
{
public void run()
{
System.out.println("TestRunnable in " + Thread.currentThread().getName());
}
}
Output if only start
is called:
TestRunnable in Fred
Output if only run
is called:
TestRunnable in main
If start
isn't called, then the Thread
created will never run. The main thread will finish and the Thread
will be garbage collected.
Output if neither is called: (nothing)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…