04_Java-Concurrency
04_Java-Concurrency
Timeout
Ready
to Run Sleeping
Scheduled
Wait
Yield
Sleep
Stop Revoked
Running
Completed
Dead
I/O Completed
Lock acquired Blocked
Three ways to create threads
• Extend Thread
• Implement Runnable
• Implement Callable
– Able to return an object
– Supports typed exceptions
Constructs
• Wait
• Notify
• NotifyAll
• Interrupt
• Sleep
• Join
• Synchronized
• Volatile
• Yield
Deadlock
• Atomicity
– Prevention of interference through locking and mutual exclusion
• Visibility
– Everything in one synchronized block occurs before and is visible
to everything in a later block
• Ordering
– Ensuring that you aren’t surprised by the order in which
statements are executed
Pitfalls
18