Title: Threads Summary
Course: CPS 261: Advanced Java Concepts ~ DL & MM MASTER

Threads Summary

Thread Fundamentals

- Examples of where Threads are used.
- Creating a thread by extending the Thread class
- Creating a thread by creating a class which implements the Runnable interface
- Managing threads using the interrupt, isAlive methods. Note that the actual thread will experience an InterruptedException.

Thread Synchronization

- Synchronization issues when multiple threads access common data. Bank.java illustrates the problem that can occur.
- Using the keyword "synchronized" to fix the problem. You can also use "synchronized" to mark a block of code that needs to be protected. Java enforces the rule: only one thread can be in any synchronized section of an object instance at any one time.
- Deadlocks - Deadlock.java is an example (simple but contrived) of a deadlock that can occur when synchronized regions are not properly handled.

Threading Wait Notify capabilities

- BusyLoop.java example: Busy loop approaches to working with synchronized objects is wasteful on resources.
- WaitNotify.java example: Using wait, notify, and notifyall (all methods found in the Object class), you can produce a more efficient approach.
- WaitNofity2.java - A circular queue of buckets using wait, notify, and notifyall to produce an even better approach. Parallel_IO.java is a more practical example of the same technique. This is something I found very useful to know about in industry.
- Optional Extra (and fun) examples: Dining Philosopher problem, Color Boxes example, and the Pizza store problem.

Last Modified: June 8, 2014 9:57 AM