Java Threads Workshop - Example Applets

IPCA : Groups : Wotug : Java : Applets

[ News | IPCA | Mirrors | Add | Search | Mail | Help | WoTUG ]

(Updated 10th February 1997)

Java Threads with Channels

This page describes two different Java applets that demonstrate the occam-style CHAN mechanism implemented in Java.

Single Reader and Writer Demonstration (StatusControl Applet)

This is a simple applet consisting of two Java threads controlling two elements: a button (control thread) and a label (status thread). The status thread increments the status value every second. If the button is pressed, the control thread sends a message via a CHAN_OF_INT Class (Documentation) to the status thread. When the status thread sees the channel is not-empty (by polling it), the message is read and the counter reset.

See the Source Code of the CHAN_OF_INT class and the StatusControl class (the applet) for further details.

Java Status Control applet requires a browser that runs Java.

Multiple Readers and Writers Demonstration (ReadChanWrite Applet)

This applet demonstrates a multiple-readers/writers Channel c (Documentation) which carries Java Objects. The applet consists of writer threads on the left and reader threads on the right.

The writers OR readers can be active as buttons in which case the user has control.

Active Readers

When the readers are active, the writers are eager to send and block on outputing (queueing on the Channel). You can decide which reader should pick up the next written value by clicking on one of the Readers. When that happens, the reader will do a read() on the shared Channel and the value (from the Writer at the front of the queue) will be displayed. Note that the Writer threads queue fairly.

Java ReadChanWrite applet requires a browser that runs Java.

Active Writers

In this example, the readers are eager to receive and are blocked on inputting (again queueing on the Channel). You can decide which writer should send the next value by clicking on one of the writers. When that happens, the given Writer will do a write() on the shared Channel and the value will be displayed and transfered to the next queued Reader. Note again that the Reader threads queue fairly.

Java ReadChanWrite applet requires a browser that runs Java.

Note: In each of the examples there are Java threads (Active Objects) for each Reader and Writer and a single Channel (Passive Object).

See the Source Code of the Channel class and the ReadChanWrite class (the applet) for further details.

class BUFFER_OF_INT

This is the Source Code of the BUFFER_OF_INT class as discussed in the handouts (see main Java Threads Workshop page).


Java is a Registered Trademark of Sun Microsystems Inc.
Copyright © 1993-2000 Dave Beckett & WoTUG