Programming Language Basics
Computer Science isn’t really About Programming
Nevertheless
Other Languages
Threads
Threads in Java
Creating a Thread
A Runnable Class
A Runnable Class
Creating a Thread
Creating a Thread
Creating a Thread
Syntactic Help
Anonymous Inner Class
Anonymous Inner Class
Anonymous Inner Class
Starting a Thread
Joining a Thread
Monitors
Call Center Scenario
Bad Queue Implementation
Bad Queue Implementation
Bad Queue Implementation
Bad Queue Implementation
Bad Queue Implementation
Of course, this doesn’t work
Mutual Exclusion
Mutual Exclusion
Synchronized Method
Synchronized Method
Syntactic Sugar
Syntactic Sugar
Vocabulary
Re-entrant Locks
Still Doesn’t Work
Still Doesn’t Work
Waiting
Waiting Synchronized Method
Waiting Synchronized Method
Deadlock
Waiting Thread
Styles of Waiting
Styles of Waiting
The wait() Method
The wait() Method
Waiting Synchronized Method
Waiting Synchronized Method
Wake up and Smell the Coffee
The wait() Method
The wait() Method
The wait() Method
The wait() Method
The wait() Method
The wait() Method
Lost Wakeup
Empty queue, waiting dequeuers
Enqueuer puts item in queue
Since queue was empty, wakes dequeuer
1st Dequeuer slow, overtaken by enqueuers
1st Dequeuer finishes
Solutions
Thread-Local Data
Thread-Local Data in Java
ThreadLocal methods
ThreadLocal methods
Initializing ThreadLocals
Example
Thread-Local IDs
Thread-Local IDs
Thread-Local IDs
Thread-Local IDs
The Inner Class
The Inner Class
The Inner Class
Summary