To Cliser Home

Cliser: The Java ThreadManager Class

To Cliser Architecture

Cliser's Java ThreadManager class provides a convenient means of managing a pool of reuseable threads. A Cliser (Java) ConcurrentServer uses a ThreadManager to reduce the time-expense associated with multithreaded operation.

Cliser's Java Thread Manager

A ThreadManager increases a server's time-efficiency by creating a pool of threads when it is instantiated. Upon receiving a getThread() message, a ThreadManager simply returns the first idle thread from its pool. If all threads are busy, then the ThreadManager creates a new thread, adds it to its pool, and returns it as the return-value of getThread().

Correspondingly, when a thread completes its service, it must inform its ThreadManager that it is no longer busy. Since the standard Java Thread class does not provide this behavior, Cliser uses a custom ServiceThread class that provides this functionality, and Cliser's code generator extends this ServiceThread class when the user specifies that they require a concurrent server in Java.

The Cliser ThreadManager is based the Prototype programming pattern. As such, the constructor of a ThreadManager must be given an instance of the thread it is to store in its thread pool. In Cliser, this thread will generally be a subclass of ServiceThread.

Since the ThreadManager must replicate this thread, our Java ServiceThread implements the Cloneable interface. This allows the ThreadManager to replicate the ServiceThread subclass it receives by sending it the clone() message (which ServiceThread must define).

By creating a pool of threads at the outset and maintaining this pool so as to reuse each thread in the service of different clients, the ThreadManager avoids the overhead associated with thread creation and destruction.


Up to the Cliser class libraries Back to the Communicator class hierarchy Forward to the CommunicatorUser class hierarchy Up to the C++ class library

This page maintained by Joel Adams (adams@calvin.edu).