Sun Java System Messaging Server 6 2005Q4 MTA Developer's Reference

How Dequeuing Works

Channel programs wishing to dequeue messages from the MTA must associate themselves with a specific MTA channel or channels. Without this information, the MTA SDK does not know which channel queue to draw messages from. This information can be provided implicitly with the PMDF_CHANNEL environment variable, or explicitly by specifying the name of the MTA channel to process when calling mtaDequeueStart().

The dequeue process is initiated by calling the routine mtaDequeueStart(). A key piece of required information passed to mtaDequeueStart() is the address of a caller-supplied routine designed to process a single message. This routine will be repeatedly called by mtaDequeueStart() until there are no more queued messages in need of processing. One call is made per message to be processed.

Unless otherwise instructed, mtaDequeueStart() will use multiple threads of execution to process queued messages. Each thread of execution will repeatedly invoke the caller-supplied routine, once for each message to be processed. Thus, by default the caller-supplied routine is expected to be “thread-safe.” That is, it is expected to support being called simultaneously by more than one thread of execution. If the caller-supplied routine is not thread safe, then mtaDequeueStart() can be instructed to use a single thread of execution, as illustrated in A Complex Dequeuing Example.