The JavaTM Tutorial
Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Trail: Putting It All Together
Lesson: BINGO!

Synchronizing and Coordinating Threads

The following diagram shows the threads in both the Game and Player applications.

[PENDING: figure here]

As you can see from the diagram, the Player program uses these threads:

The Game program uses these threads:

Using Synchronized Code Segments

As the diagram shows, different threads access the same objects or data. For example, when two Players attempt to register simultaneously, the two Player threads (running in different VMs) both modify the Roster object in the Game application by adding a player to the roster. In these cases, the threads must be synchronized so that the data accesses are guaranteed to be thread-safe. This is achieved through synchronized blocks and synchronized methods in the Game application.

Synchronizing Threads in the Player

The Player application uses a customized EventQueue that handles thread synchronization automatically.

Coordinating Threads in the Game

In the Game application, some threads must coordinate their activities. For example, the GamesThread must wait until the current game is over (a condition that is set by another thread) before it can begin another game. In such a case, the threads coordinate with one another using wait and notifyAll.

Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form