O'Reilly logo

Seven Concurrency Models in Seven Weeks by Paul Butcher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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​ IOException {
 
 
class​ ConnectionHandler ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required