O'Reilly logo

Java RMI by William Grosso

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

Chapter 11. Threads

Threads are simple. They allow a program running on a single computer to perform more than one task at a time in much the same way that an operating system allows more than one program to run at the same time. Using threads, however, can involve some subtlety. The Java programming language has extensive support for threading, both in the programming language and in the libraries that come with the JDK. In this chapter, we’ll discuss why threading is important in distributed programming and cover the fundamentals of using threads in Java.

More Than One Client

In our previous discussions on deciding on a server, I talked briefly about several issues related to scalability. The goal of those discussions was simple: we wanted to guarantee that our systems will be able to simultaneously support many different users, all of whom are attempting to perform different tasks.

But those discussions carefully dodged a very difficult question: how do we build a server that can handle more than one request at once? Consider the bank system we built in Chapter 9. If we take the existence of multiple clients into account, we wind up with the architecture diagram shown in Figure 11-1.

Architecture diagram for the bank system

Figure 11-1. Architecture diagram for the bank system

This has an important implication: the possibility exists that two separate clients will receive stubs for the same instance of Account (e.g., ...

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