Announcement Announcement Module
Collapse
No announcement yet.
Multithreading with a gateway at the beginning using a queue Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Multithreading with a gateway at the beginning using a queue

    Hi,

    I'm trying to figure out, how can I do some steps in parallel to safe some time in my processing.
    So I defined following test:


    Code:
    	<int:gateway service-interface="de.firstdata.ewas.integration.IThreadTestGateway" 
    		default-request-channel="input" />
    
    	<int:channel id="input"/>
    
    	<int:service-activator ref="testActivator" method="test" input-channel="input" output-channel="delayChannel" />
    
    	<bean id="testActivator" class="de.firstdata.ewas.integration.ThreadTestServiceAccessor" />
    
    	<int:channel id="delayChannel" >
    			<int:queue capacity="100"/>
    	</int:channel>
    	
    	<int:delayer default-delay="1000" input-channel="delayChannel" />
    
    	<int:poller default="true" max-messages-per-poll="100" task-executor="executor">
    		<int:interval-trigger interval="10" time-unit="MILLISECONDS"/>
    	</int:poller>
    
    	<task:executor id="executor" pool-size="100" queue-capacity="100"/>
    Somehow I excpected, that the delay will be done asynchronously, but it's not. I know, that the gateway is normaly for synchronous operation, but is there a chance to get steps running asynchronously?

    Thanks a lot in advance

    joachim

  • #2
    Well, gateway is Not for sync communication. You can easily do async with async gateway.
    I'd suggest to look at this example https://github.com/SpringSource/spri.../async-gateway and also read this section of the manual http://static.springsource.org/sprin...#async-gateway

    As far as your specific configuration, the delayer is subscribing to a polling channel so it itself must have a poller configuration or use the default poller.

    Comment


    • #3
      Hi Oleg,

      perfect. Thanks!!
      And also thanks a lot for your webinar last week. Looking forward for the next one.

      If there is anybody interested, here my new configuration:

      Code:
      	<int:gateway service-interface="de.firstdata.ewas.integration.IThreadTestGateway" 
      		default-request-channel="input" />
      
      	<int:channel id="input" >
      			<int:queue capacity="100"/>
      	</int:channel>
      	
      	<int:delayer default-delay="1000" input-channel="input" >
      		<int:poller max-messages-per-poll="10" task-executor="executor">
      			<int:interval-trigger interval="10" time-unit="MILLISECONDS"/>
      		</int:poller>
      	</int:delayer>
      
      	<task:executor id="executor" pool-size="100" queue-capacity="100"/>
      And of course a different call in the source code:

      Code:
      		final ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:threadTest.xml");
      		final IThreadTestGateway gw = ctx.getBean(IThreadTestGateway.class);
      
      		final List<Future<String>> resultList = new ArrayList<Future<String>>();
      		for (int i = 0; i < 100; i++) {
      			final Future<String> result = gw.test("testme"+i);
      			resultList.add(result);
      		}
      
      		for (final Future<String> future : resultList) {
      			try {
      				System.out.println(future.get(2000, TimeUnit.SECONDS));
      			} catch (final Exception e) {
      				e.printStackTrace();
      			}
      		}
      Joachim
      Last edited by mySpringUser; Apr 26th, 2012, 03:58 AM. Reason: Added source code

      Comment

      Working...
      X