Results 1 to 5 of 5

Thread: Is it safe using Spring Integration in web application from threading perspective ?

  1. #1
    Join Date
    Oct 2008
    Posts
    18

    Question Is it safe using Spring Integration in web application from threading perspective ?

    Hi,

    I consider using Spring Integration in web application.

    But, I am worrying that creating thread (like Poller) by application in web container harm ap server's resource management.

    How Spring Integration manage thread ?
    Is it safe using Spring Integration in web application from threading perspective ?

    Thanks.

  2. #2
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,037

    Default

    Spring provides abstractions for that; see WorkManagerTaskExecutor and TimerManagerTaskScheduler...

    http://static.springsource.org/sprin...cheduling.html

    Simply use a TimerManagerTaskScheduler (for pollers) as described here...

    http://static.springsource.org/sprin...-taskscheduler

    ...and use a WorkManagerTaskExecutor for any element that needs a TaskExecutor for asynchronous operations.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  3. #3
    Join Date
    Oct 2008
    Posts
    18

    Default

    Thank you for reply !

    I tryed to use WorkManagerTaskExecutor for JMS inbound message handling,
    but I can't see my expected behavior.

    I declare WorkManagerTaskExecutor and message-driven-channel-adapter below.

    Code:
        <bean id="taskExecutor" class="org.springframework.scheduling.commonj.WorkManagerTaskExecutor">
          <property name="workManagerName" value="java:comp/env/wm/MyWorkManager" />
        </bean>
        <jms:message-driven-channel-adapter
            id="inboundAdapter" 
            channel="channel2" 
            destination-name="sampleQueue" 
            max-concurrent-consumers="30"/>
    And, I set ap server's WorkManager max threads to 5 (I use myFoo commonJ with Tomcat).

    So, my expected behavior is jms consumer concurrent thread limits by 5 (becase ap server's max thread is 5).
    But, fact is conurrent 30 threads naming "org.springframework.jms.listener.DefaultMessageLi stenerContainer" arrive.

    Is my expectation (concurrent thread limt by 5) wrong ?
    Or my setting is insufficient ?

    Thanks.

  4. #4
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,037

    Default

    You need to tell the adapter's message listener container to use your configured task executor; this is not directly available on the adapter using the namespace.

    Declare a bean of type DefaultMessageListenerContainer, set the taskExecutor property (and the others such as concurrency), and provide it to the adapter using the 'container' attribute.

    JavaDoc for DMLC.setTaskExecutor...

    Code:
    	/**
    	 * Set the Spring {@code TaskExecutor} to use for running the listener threads.
    	 * <p>Default is a {@link org.springframework.core.task.SimpleAsyncTaskExecutor},
    	 * starting up a number of new threads, according to the specified number
    	 * of concurrent consumers.
    	 * <p>Specify an alternative {@code TaskExecutor} for integration with an existing
    	 * thread pool. Note that this really only adds value if the threads are
    	 * managed in a specific fashion, for example within a J2EE environment.
    	 * A plain thread pool does not add much value, as this listener container
    	 * will occupy a number of threads for its entire lifetime.
    	 * @see #setConcurrentConsumers
    	 * @see org.springframework.core.task.SimpleAsyncTaskExecutor
    	 * @see org.springframework.scheduling.commonj.WorkManagerTaskExecutor
    	 */
    	public void setTaskExecutor(Executor taskExecutor) {
    		this.taskExecutor = taskExecutor;
    	}
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  5. #5
    Join Date
    Oct 2008
    Posts
    18

    Default

    I see, I changed my bean definition to...

    Code:
        <bean id="sampleQueueListenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
            <property name="taskExecutor" ref="taskExecutor"/>
            <property name="connectionFactory" ref="connectionFactory"/>
            <property name="destinationName" value="sampleQueue"/>
        </bean>
        <jms:message-driven-channel-adapter
            id="inboundAdapter" 
            channel="channel2" 
            container="sampleQueueListenerContainer"/>
    I tried, and it seems to use ap server's WorkManager.

    Thank you for your kindness.

Posting Permissions

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