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.
Get Java Threads, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.