There is nothing stopping you from starting the thread in the same line as the constructor (Code
Example 4-11 Construct and Start in a Single Line
APIs Used in This Chapter
The Class java.lang.Thread
The class Thread defines thread objects. When the start() method is called, an actual running
thread is created which the Thread object can control. It is important to distinguish between the
object (which is just memory and a set of methods) and the running thread (which executes code).
All static thread methods apply to the current thread.
Thread(Runnable runObj, String name)
These create a new thread object.
public void start()
Calling the start() method on an instance of Thread will cause the appropriate run() method
to execute in a new thread.
public void run()
This is the method you define that actually executes the code you want. The base method simply
looks to see if there is a Runnable and calls its run() method.
public static Thread currentThread()
This method returns the current thread object.
Search WWH :