NEW State: Thread Creation
What you'll learn: You'll understand when a thread enters the NEW state and what you can safely do with it before calling start().
What Is the NEW State?
When you create a Thread object (either by instantiating the Thread class or passing a Runnable to its constructor), the thread immediately enters the NEW state. This is the thread's "birth" moment—it exists as a Java object in memory, but it hasn't yet been scheduled by the operating system to run any code.
Think of it like buying a ticket to a concert. You have the ticket (the thread object exists), but you're not yet in the venue or watching the performance. You're simply ready to go.
Valid Operations in NEW State
While in NEW state, a thread is just a regular Java object. You can:
- Set its name using
setName() - Configure properties (though most thread configuration must happen before starting)
- Store a reference to it
- Pass it around to other methods
What you CANNOT do: You cannot make the thread execute its task. Calling start() is what transitions the thread out of NEW state.
Example Scenario
Thread t = new Thread(() -> System.out.println("Hello"));
// t is now in NEW state
t.setName("MyThread"); // Valid operation
System.out.println(t.getState()); // Prints: NEW
The thread remains in NEW until start() is invoked. Once started, it can never return to NEW—attempting to call start() again throws IllegalThreadStateException.
Key Takeaway: A thread enters the NEW state the moment its object is created and remains there until start() is called—during this time, it's just an ordinary object with no execution scheduled yet.