More Multithreading
- Download example code: downloads/multithreading
- Joining Threads
- You can coordinate threads by using join().
- You can coordinate threads by using join().
- This will cause the current thread to wait for another thread to complete (die) before it continues.
- The join() method can throw an exception, so must be in a try/catch block.
- If the thread that starts the other threads does not wait, it will end while the others will continue to execute.
- These child threads are called orphans.
- Joins (Oracle Tutorials)
- Synchronization
- Deadlock and Starvation
- Wait and Notify
- Thread Pools
- A Thread Pool allows you to create a list of Threads and as requests come in, assign a particular thread to complete the task.
- Each thread is called a worker thread.
- The Java Executor interface is used to implement a thread pool.
- Example code: TaskExecutor.java
- Executors (Oracle Tutorials)
- Thread Pools (Oracle Tutorial)