Rummaging through my virtual attic (actually, the sources to what was
going to be Apache JServ 2.0 before Tomcat came along), I've found a bunch
of useful classes that assist in building multi-threaded applications --
especially message passing and thread synchronization --
which we do a lot of in Jakarta-land. I was wondering if people thought
this might be a useful package to consider for Commons. If there's
interest, I'll go pull the stuff out and check it into sandbox so we can
take a look.
The proposed package name would be "org.apache.commons.threading"..
Included interfaces:
* Notifier - Implements a background thread that delivers objects
to specified Subscribers
* Publisher - Interface implemented by senders who want to send messages
to registered Subscribers
* Queue - Generic message queue interface
* Semaphore - Generic interface for objects that represent locks or
semaphores
* Subscriber - Interface implemented by receivers who want to receive
messages sent by Publishers
Included classes:
* Alarm - Timer that publishes events in one of three modes: continuous
(at regular intervals), multi-shot (fires once, but can be reused), and
one-shot (fires once, then destroys background thread)
* AsynchPublisher - Publisher that uses a Notifier for delivery via a
shared or unshared background thread
* Condition - Simple condition variable for use in flags like "queue
not empty"
* Counter - Counting semaphore that can be used to suspend a receiver
until there is at least one object in a Queue
* FIFONotifier - Implementation of Notifier that guarantees to deliver
notifications in the order received, with no dropped notifications
* FIFOQueue - Implementation of queue with first-in/first-out semantics
* LIFOQueue - Implementation of queue with last-in/first-out semantics
* MultiSemaphore - Utility class for locking and unlocking multiple
semaphores at once
* Mutex - Semaphore that can be locked by only one thread at a time
* SynchPublisher - Publisher that uses the caller's thread for delivery
NOTE: A lot of these classes were inspired by an article series by Allen
Holub called "Java Threads in the Real World", published in JavaWorld from
September 1998 through April 1999. I've used them in a variety of
scenarios to good effect, and would like to see them available.
Craig