How Channels Use Threads

An inlet is the component of a channel that accepts and prepares messages for execution. In an inlet, the portion that accepts and prepares messages for execution is called a listener. Listeners implement the specific protocol that is required to obtain the message. The listener is also the component that is responsible for thread configuration.

Each listener executes in its own thread and never shares resources with other listeners. iSM starts and stops listeners, and gathers and distributes statistics on their operation. Listeners are designed to be reasonably inactive. They mostly await events and prepare them for execution. The execution is delegated to a worker thread, which in iSM is called a worker. When you set the thread count for a listener, you are declaring how many workers that listener has available to accept and process work. A message is only bound to a worker during its execution, from when it is ready to be processed until the processing is complete. The completion of a process is not meant in a business sense, rather the handling on the message until the current operation is completed.

Because workers take time to start up and shut down, iSM allocates a pre-initialized set of workers to each listener, called the listener's worker pool. The Multithreading configuration parameter on the listener configuration instructs iSM startup on how many workers are to be allocated to the pool. This parameter is available for all listeners. When a message arrives, the listener selects a worker from the pool, assigns the message to it, and then moves on to await the arrival of the next message.

The consequence of the multithreading value varies among protocols. Protocols that manage queues, such as any of the queue listeners (for example, MQ or internal), accept a message and request a worker for its execution. The listener waits until a worker is available and then hands off the work. If the number of workers is less than the number of messages in a queue, the messages wait in the queue until a worker is available for their execution. Given an expected arrival distribution and estimated time of service for a message, you can calculate how long a message will wait.