-
Notifications
You must be signed in to change notification settings - Fork 3
kiwi.lang.Thread wait() and notify() Methods in Kiwi
Nikos Siatras edited this page Oct 4, 2022
·
26 revisions
In this tutorial, we'll look at one of the most fundamental mechanisms in Kiwi — thread synchronization. We'll first discuss some essential concurrency-related terms and methodologies. And we'll develop a simple application where we'll deal with concurrency issues, with the goal of better understanding wait() and notify().
In a multithreaded environment, multiple threads might try to modify the same resource. Not managing threads properly will of course lead to consistency issues.
One tool we can use to coordinate actions of multiple threads in Kiwi is guarded blocks. Such blocks keep a check for a particular condition before resuming the execution. With that in mind, we'll make use of the following:
- KObject.wait() to suspend a thread
- KObject.notify() to wake a thread up
We can better understand this from the following diagram depicting the life cycle of a Thread:
- MySQL/MariaDB - Coming to v1.0.2
- ArrayList
- Comparator
- HashMap - Coming to v1.0.2
- Queue