Summary

In this chapter, we have taken a look at some real examples of threads in action along with the issues of their synchronization. As we started to do in the previous chapter, we are now using threads simply as an implementation tool. We have started new threads and communicated between these threads, but users of our classes are not concerned with and may not even know that these threads exist.

We have also examined synchronization issues in cases where we have not started any threads at all. A simple item like a container class must be designed with threading in mind. This is because, although we may not start any threads, we are already threaded in our program. We must think of threading as not only an implementation detail in our classes, but also in all other classes in the system. Threading issues like deadlock and race conditions should always be involved in our class designs, whether or not we actually use threads in our classes at all.

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.