Summary
In this chapter, we introduced the synchronized
keyword of the Java language. This keyword allows us to synchronize
methods and blocks of code.
We’ve also developed a synchronization primitive of our own:
the BusyFlag, which allows us to lock objects across methods and to
acquire and release the lock at will based on external events. These
features are not available with Java’s
synchronized keyword, but they are useful in many
situations.
This concludes our first look at synchronization. As you can tell, it is one of the most important aspects of threaded programming. Without these techniques, we would not be able to share data correctly between the threads that we create. While these techniques are good enough for many of the programs we will be creating, we introduce other techniques in the next chapter.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access