Results 1 to 5 of 5

Thread: Dedicated thread per subscriber?

  1. #1

    Default 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. #2
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    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

  3. #3

    Default 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

  4. #4
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    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.

  5. #5

    Default

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •