Threads
Objectives
Applied
- Use the Thread class or the Runnable interface to create a thread.
- Use the methods of the Thread class to control when the processor executes a thread.
- Use the interrupt method and the InterruptedException class to create a thread that can be interrupted.
- Use the synchronized keyword to create synchronous threads.
- Use the wait and notifyAll methods of the Object class to coordinate the execution of two interdependent threads.
Knowledge
- Explain the basic difference between a program that runs in a single thread and a program that runs under multiple threads.
- Name three common reasons for using threads in a Java application.
- List the three Java API classes or interfaces that have methods related to threading.
- Explain the advantage of creating a thread by extending the Runnable interface rather than by inheriting the Thread class.
- List the five states of a thread, and describe the status of a thread in each state.
- Explain the difference between the sleep and yield methods.
- Explain why methods that can be executed concurrently by multiple threads need to be synchronized.
- Describe the producer/consumer pattern used for concurrency control.