Java Multitasking  «Prev 

Podium Speaker Coordination at TownHall

We could use a little coordination among all these speakers. Here is the class we will use to help with this task.
We mentioned SynchronizedQueue a short while back. Let us deal with that new class now.
The podium will be represented by this subclass. We will create this subclass to be a kind of magical and fair podium.
When a speaker says something, the podium will ensure that the speaker's message does not overlap someone else's message and squash that person's equally precious two cents. we will use the keyword synchronized to do this, as we will describe in just a moment. Here is the outline for our podium subclass:

 class SynchronizedQueue extends Vector {

    private int count;  
    private boolean started; 
    SynchronizedQueue() {  
       count = 0;  
       started = false;  
    } 
}

As you can see from the class definition, the podium knows how many messages are waiting to be delivered and whether people have started speaking yet. We will use this class to help coordinate among the speakers, but we still have code to write.

What the speakers say

So what gets said? At this town hall, the citizens are up in arms. There are quite a number of issues on their minds, and they do not hesitate to raise them! We will cover the rest of the town hall application after you have been introduced to the life cycle of a thread.