Chapter 11. Threads and Networking

Table of Contents

Introduction
Threads - An Introduction
Introduction
Multiprocessing vs. Multithreading
Why use threads?
Threads - A better way?
A Working Counter
Threads - More Aspects
Suspending and Resuming Threads
Try this yourself! - An Up/Down Counter
Scheduling of Threads
Thread Priorities
An Example of Priorities and Threads
Synchronization of Threads
Introduction
A Good Bad Example
Adding Synchronization to Code
A Multi-Threaded TCP Server
Introduction
An Exercise For You. The Random Draw Thread

Introduction

This tutorial assumes that you have completed Chapter 10, Networking in Java - Client/Server Applications. The client-server application that was discussed in that tutorial worked well, however there was one main difficulty. The Server could only handle one client connection at a time, i.e. A connection is made and the server is locked to that client. The service is performed and then when complete, the client is released and the server is available for more client connections. In this section we want to develop a threaded server that will allow multiple client connections at the same time.