Announcement Announcement Module
Collapse
No announcement yet.
Is it safe using Spring Integration in web application from threading perspective ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      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.

      Comment


      • #4
        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;
        	}

        Comment


        • #5
          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.

          Comment

          Working...
          X