Lesson 10
Java Multithreading Conclusion
The following list summarizes the important points about threads that were covered in this module:
- The task scheduler implements multithreading support by quickly switching between the threads that are executed by a system's CPU or CPUs.
- Threads may be created by extending the
Thread
class or implementing the Runnable
interface.
- A thread's
run()
method is its entry point.
- The
start()
method of the Thread
class is invoked to start a thread executing as a separate sequence of instructions. This results in the thread's run()
method being invoked by the JVM.
- Thread states are New, Runnable (ready), running, waiting, and dead.
- The thread scheduler moves threads from the Runnable (ready) state to the running state.
- Threads are scheduled based on their priority and the operating system's scheduling algorithm (preemptive scheduling or time slicing).
- A thread may invoke its
yield()
method to move from the Running state to the Runnable (ready) state.
- A thread may move from the Running state to the waiting state as the result of invoking its
sleep()
method, blocking on I/O, waiting for a lock, or invoking an object's wait()
method.
- A thread enters the dead state when its
run()
method returns.
- Synchronization coordinates access to shared objects among multiple threads.
- Synchronization is maintained through the use of locks.
- The
wait()
, notify()
, and notifyAll()
methods can be used to cause threads to wait until an object is updated by another thread.
What is the purpose of the task scheduler in the Java 1.0 Model?
The task scheduler in the Java 1.0 model is responsible for managing and scheduling tasks or threads that are running within the Java Virtual Machine (JVM). It is responsible for allocating system resources to the various threads and ensuring that they are executed in a timely and efficient manner. The task scheduler is also responsible for managing the priority of threads, and for ensuring that the most important threads are given priority over less important threads. This helps to ensure that the JVM runs efficiently and that the most important tasks are completed in a timely manner.
Key terms and concepts
- Thread: A sequence of statements that is executed as part of a program
- Multithreaded program: A program that simultaneously supports more than one thread of execution.
- Thread scheduler: The part of an operating system that assigns threads to CPUs, also referred to as the scheduler.
- Scheduler: The part of an operating system that assigns threads to CPUs, also referred to as the thread scheduler.
- Execution state: The states occupied by a thread during the course of its execution.
- Scheduling: The assignment of threads to CPUs.
- Thread priority: A ranking of threads that determines their likelihood of being scheduled.
- Preemptive scheduling: An approach to scheduling in which the highest priority thread continues to execute until it enters a wait state or a higher priority thread comes into existence.
- Time slicing: A scheduling approach in which a thread executes for a slice of time and then enters a waiting state while another (possibly same) thread is scheduled.
- Synchronization: The coordination of multi-thread access to shared objects
- Entry point: The first method that is executed when an application (main()), thread (run()) is executed.
- Lock: A mechanism for implementing shared access to an object, also referred to as a monitor
Thread Concepts - Exercise
Multithreading - Quiz