Download presentation
Presentation is loading. Please wait.
1
Synchronized Threads and Threads Coordination
2
Synchronized Threads Run the program in syncPackage.
This program creates 2 threads, which work on the same instance of CommandClass. This results in a race condition, which is usually bad. Notice the CommandClass, the synchronized(this){} block is the region that only one thread can have access to at anytime. What happens if you delete synchronized(this) and its curly braces?
3
Threads Coordination In package main.
Each vehicle is controlled by a thread. These 3 threads share a common instance of clearance manager. Notice the wait() call (in method waitforproceed) in clearance manager. This function call will temporally put the current thread(the thread that made the call) into waiting state and let other threads run. The thread can wake up if other thread make the notify call (in method proceed and proceedAll)
4
If there are multiple threads waiting for notify(), each time notify will wake up a single thread in the waiting queue. Queue is a first in, first out data structure. notifyAll will wake up all threads in the waiting queue.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.