Re: ServerSocket readLine() problem in a special situation
Lew wrote:
M sits in a tight loop listening for messages or requests for messages
from its clients, and immediately forwarding the posted messages to
agents or other recipients for action.
"What if the destination isn't ready yet?" you ask? Excellent question.
M will need some storage to hold messages until their destinations finally
request them.
Likewise, if A calls for messages and there aren't any, M will put A on hold
until there are, then go back to looping for incoming dispatch orders.
M's loop is very fast, but it needs capacity to handle latency between its
clients. This is where Roedy's suggestion to use queues can be useful, also
stacks and deques. Java 6 has a panoply of such interfaces and their
implementations, e.g.,
<http://java.sun.com/javase/6/docs/api/java/util/Stack.html>
<http://java.sun.com/javase/6/docs/api/java/util/Deque.html>
I admit, it weirds me out that Stack inherits from Vector. Then again, it
does date from 1.0. Then again again, in Stack's Javadocs Sun advises
A more complete and consistent set of LIFO stack operations is provided by
the Deque interface and its implementations, which should be used in preference to this class.
It looks like Deque is Stack's ArrayList.
If you need concurrency, omigosh, there's a ton of that over in
<http://java.sun.com/javase/6/docs/api/java/util/concurrent/package-frame.html>
Just read the class names down the list out loud: "AbstractExecutorService,,
ArrayBlockingQueue, ConcurrentHashMap, ConcurrentLinkedQueue, ...,
LinkedBlockingDeque, LinkedBlockingQueue, PriorityBlockingQueue, ...,
SynchronousQueue, ..."
Sheer poetry.
--
Lew