Results 1 to 3 of 3

Thread: Multithreading with a gateway at the beginning using a queue

  1. #1

    Default 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. #2
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    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.

  3. #3

    Default

    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 at 03:58 AM. Reason: Added source code

Tags for this Thread

Posting Permissions

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