Day 3: On the Shoulders of Giants

As well as the enhanced locks we covered in day 2, java.util.concurrent contains a collection of general-purpose, high-performance, and thoroughly debugged concurrent data structures and utilities. Today we’ll see that more often than not, these prove to be a better choice than rolling our own solution.

Thread-Creation Redux

In day 1 we saw how to start threads, but it turns out that it rarely makes sense to create threads directly. Here, for example, is a very simple server that echoes whatever it’s sent:

ThreadsLocks/EchoServer/src/main/java/com/paulbutcher/EchoServer.java
​ 
​public​ ​class​ EchoServer {
​ 
​ 
​public​ ​static​ ​void​ main(​String​​[]​ args) ​throws ...

Get Seven Concurrency Models in Seven Weeks 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.