Port of schuchert.wikispaces.com


TddAndConcurrency.Slides.DoOneThingWellWell

TddAndConcurrency.Slides.DoOneThingWellWell

Up

Do One Thing … Well … Well

Focus, Focus, Focus

You’ve heard it…

It’s even more important here

Why?

A Simple Server

Imagine a server that forever…

    ServerSocket serverSocket = new ServerSocket(8009);
    
    while (true) {
        Socket socket = null;
        try {
             socket = serverSocket.accept();
             String message = getMessage(socket);
             process(message);
        } finally {
             close(socket);
        }
    }


And its client

Now we need a client that…

    Socket socket = new Socket("localhost", PORT);
    sendMessage(socket);
    getMessage(socket);
    socket.close();


You need to make this faster…

Threads to the rescue, right?

    ServerSocket serverSocket = new ServerSocket(8009);
    Socket socket = null;
    socket = serverSocket.accept();
    close(socket);
    getMessage(socket);
    process(message);

Up


Comments

" Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.