Announcement Announcement Module
Collapse
No announcement yet.
Dedicated thread per subscriber? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dedicated thread per subscriber?

    I have configured a pub-sub channel, and would like to have a single dedicated thread per subscriber (each subscriber is a service-activator.) Is it possible?

    Thanks,
    Khoa

  • #2
    Sure. It sounds like you just want to add a reference to an Executor instance via the publish-subscribe-channel element's "task-executor" reference. You can even use Spring's "task" namespace to configure the Executor. Details are here: http://static.springsource.org/sprin...task-namespace

    Comment


    • #3
      Re: dedicated thread per subscriber

      Thanks Mark for your inputs. However, with the following config:
      Code:
      <publish-subscribe-channel id="dataChannel" task-executer="workers"/>
      <task:executor id="workers" pool-size="5"/>
      
      <service-activator id="a" input-channel="dataChannel" .../>
      <service-activator id="b" input-channel="dataChannel" .../>
      ...
      isn't it true that each service-activator may be running concurrently and not single-threaded? I would like to pin a single thread to each service-activator since the service-activator implementation is not thread-safe.

      Thanks,
      Khoa

      Comment


      • #4
        Well, if you really want to have exactly one thread per service activator, then you should probably use a simple <channel> as the input of each service-activator and then add a <dispatcher> sub-element to each of those that has a task-executor reference that is a single threaded executor. To connect all of those to a single publish-subscribe-channel you could use <bridge> elements. Simpler, but probably overly serialized, you could just use a single-threaded executor on the publish-subscribe-channel (overly serialized in this case meaning that you would not even have concurrent invocation of the different service-activator instances).

        Personally, I would really try to make the service thread safe instead, even if that means adding 'synchronized' blocks to avoid concurrency at that level.

        Comment


        • #5
          Thanks again. I will try the <bridge> option first since it requires no code changes :-) Making it thread-safe will be phase 2...

          Regards,
          Khoa

          Comment

          Working...
          X