Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

are spring integration channels single threaded?

If I have a rest service then, I know for sure that each request is treated by a separate thread and the threads can run in parallel.

What happens if I have a rest(http) service as inbound channel in spring integration. Will each request still be treated in parallel or the requests will be placed in queues... and it will be more like single threaded

like image 260
Roxana Avatar asked Jul 26 '13 07:07

Roxana


People also ask

What is Channel in Spring Integration?

A channel in Spring Integration (and indeed, EAI) is the basic plumbing in an integration architecture. It's the pipe by which messages are relayed from one system to another.

Is Java single threaded or multi-threaded?

Introduction. Java supports single-thread as well as multi-thread operations. A single-thread program has a single entry point (the main() method) and a single exit point.

Is JVM single threaded?

The OS sees JVM as a single process and a single thread. Therefore, any thread created by JVM is supposed to be maintained by it only. Green threads hold all the information related to the thread within the thread object itself.

Why is single threaded better than multi-threaded?

The main difference between single thread and multi thread in Java is that single thread executes tasks of a process while in multi-thread, multiple threads execute the tasks of a process. A process is a program in execution.


2 Answers

Normal channels (DirectChannel) use the same execution thread as the object that put something into the channel (they are basically a way of abstracting a method call), so they are multi threaded.

From the docs:

In addition to being the simplest point-to-point channel option, one of its most important features is that it enables a single thread to perform the operations on "both sides" of the channel. For example, if a handler is subscribed to a DirectChannel, then sending a Message to that channel will trigger invocation of that handler's handleMessage(Message) method directly in the sender's thread, before the send() method invocation can return.


Edit

You have a very good point in your question. When you set a Queue element in a channel, spring automatically converts it to a QueueChannel (documentation), and as far as I can remember only one thread will be able to consume from the queue at at time. If you want "real" queue semantics (several producer and consumer threads) you can use an ExecutorChannel

like image 83
Augusto Avatar answered Sep 30 '22 06:09

Augusto


When using Rest (http), the threading is managed by the servlet container; containers support multiple concurrent requests but setting the concurrency is done in the container, not Spring Integration.

With default Direct channels, the container threads will invoke the Spring Integration flow concurrently on the container threads.

like image 25
Gary Russell Avatar answered Sep 30 '22 04:09

Gary Russell