Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: jdbc inbound channel adapter for doing only a single query at runtime

  1. #11
    Join Date
    Nov 2009
    Location
    Montreal, Quebec
    Posts
    398

    Default

    Mark - yes I do plan to add more logic to this application. I'm still in the early stages of the app right now which involves fetching some initial data from one datasource to then process it and eventually insert it into a second datasource.

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

    Default

    If you define a "taskScheduler" bean explicitly, you can set its 'waitForTasksToCompleteOnShutdown' property to TRUE. Then when the context tries to stop the scheduler, it should wait until the currently running task (your poller) completes.

  3. #13
    Join Date
    Nov 2009
    Location
    Montreal, Quebec
    Posts
    398

    Default

    Would I then reference that bean in the "task-executor" attribute of my poller?

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

    Default

    No, that's not necessary, if the bean's name is "taskScheduler" it will automatically replace the default instance.

  5. #15
    Join Date
    Nov 2009
    Location
    Montreal, Quebec
    Posts
    398

    Default

    Maybe I'm doing something wrong. I've added the following taskScheduler bean to my config, but the app still seems to terminate before the poller is done.

    Code:
    	<beans:bean id="taskScheduler" class="org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler">
    		<beans:property name="waitForTasksToCompleteOnShutdown" value="true"/>
    	</beans:bean>

  6. #16
    Join Date
    Nov 2009
    Location
    Montreal, Quebec
    Posts
    398

    Default

    I believe I figured it out. Rather than calling stop() on my ApplicationContext, I need to call shutdown() on my TaskScheduler instance. So with my own Trigger implementation and my own "taskScheduler" bean defined with its "waitForTasksToCompleteOnShutdown" property set to true, this is my resulting class so far. It seems to work as expected. My inbound channel adapter runs the query once like I want, returning a Message who's payload is a List of rows. Is this the right approach?

    Code:
    @Component
    public class Client {	
    	private static ThreadPoolTaskScheduler taskScheduler;
    	
    	@Inject
    	public void setTaskScheduler(ThreadPoolTaskScheduler taskScheduler) {
    		Client.taskScheduler = taskScheduler;
    	}
    	
    	public static void main(String[] args) {
    		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/applicationContext.xml", Client.class);
    		taskScheduler.shutdown();
    	}
    }
    Including my integration.xml for completeness:
    Code:
    	<int-jdbc:inbound-channel-adapter query="select * from tblData_OutboundTrace where datediff(d, MidnightStartDate, getdate()) = 1 and Extension != '' order by MidnightStartDate asc"
    		channel="outboundTraceResults"
    		data-source="pfDataSource">
    		<poller trigger="runOnceTrigger"/>
    	</int-jdbc:inbound-channel-adapter>
    		
    	<channel id="outboundTraceResults"/>
    	
    	<service-activator id="outboundTraceProcessor" input-channel="outboundTraceResults"
    		ref="pfMessageHandler" method="processOutboundTraceResults"/>
    	
    	<beans:bean id="pfMessageHandler"
    		class="com.myco.phones.trace.PrairieFyreTraceMessageHandler"/>
    	
    	<beans:bean id="runOnceTrigger"
    		class="com.myco.scheduling.RunOnceTrigger"/>
    	
    	<beans:bean id="taskScheduler"
    		class="org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler"
    		p:waitForTasksToCompleteOnShutdown="true"/>

Posting Permissions

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