Oops Through Java Unit IV
Oops Through Java Unit IV
1. NEW: A thread that has been created but not yet started.
2. RUNNABLE: A thread that is ready to run but is either executing or waiting
for CPU time.
3. BLOCKED: A thread that is waiting to acquire a lock to enter a synchronized
block or method.
4. WAITING: A thread that is waiting indefinitely until another thread performs
a specific action.
5. TIMED_WAITING: A thread that is waiting for another thread to perform a
specific action for a specified amount of time.
6. TERMINATED: A thread that has completed its execution.
This life cycle reflects the complex interplay between Java threads and system
resources, with transitions between states managed by the Java Virtual Machine
(JVM) based on the program’s logic and resource availability.
thread1.start();
thread2.start();
In this example:
- TaskOne runs with a `Runnable` implementation, allowing it to be wrapped in
a `Thread`.
- TaskTwo directly extends `Thread`, enabling direct instantiation and `start()`
invocation.