Introduction
}Operating systems onsingle-processor computers create the illusion of concurrent execution by rapidly switching between activities, but on such computers only a single instruction can execute at once.
}Java makes concurrency available toyou through the language and APIs.
}You specify that an application contains separate threads of execution each thread has its own method-call stack and program counter◦can execute concurrently with other threads while sharing application wide resources such as memory with them.
}This capability is called multithreading.
Thread States: Life Cycle of aThread
}At any time, a thread is said to bein one of several thread states.
}A new thread begins its life cycle in the new state.
}Remains there until started, which places it in the runnable state—considered to be executing its task.
}A runnable thread can transition to the waiting statewhile it waits for another thread to perform a task.
◦Transitions back to the runnable state only when another thread notifies it to continue executing.
}A runnable thread can enter the timedwaiting state for a specified interval oftime.
◦Transitions back to the runnable state when that time interval expires or when the event it’s waiting for occurs.
◦Cannotuse a processor, even if one is available.
}A sleeping thread remains in the timed waiting statefor a designated period of time (called a sleep interval), after which it returns to the runnable state.
}A runnable thread transitions to the blocked statewhen it attempts to perform a task that cannot be completed immediately and it must temporarily wait until that task completes.
}A runnable thread enters the terminated state when it successfully completes its task or otherwise terminates (perhaps due toan error).

}At the operating-system level, Java’s runnable state typically encompasses two separate states (Fig. 26.2).
}When a thread first transitions tothe runnable state from the new state, it is inthereadystate.
}A ready thread enters the running state(i.e., begins executing) when the operating system assigns it to a processor—also known as dispatching the thread.
}Typically, each thread is given a quantum or timeslice in which to perform its task.
}The process that an operating system uses to determine which thread to dispatch is called thread scheduling.

Thread Priorities and ThreadScheduling
}Every Java thread has a thread priority that helps determine the order inwhich threads are scheduled.
}Java priorities range between MIN_PRIORITY (a constant of 1) and MAX_PRIORITY (a constant of 10).
}By default, every thread is givenpriority NORM_PRIORITY (a constant of 5). Each new thread inherits the priority of the thread that created it.

.
.

