Spring integration Spring-消息驱动通道适配器-停止一个特定的并发使用者
我使用spring集成组件连接我的流程Spring integration Spring-消息驱动通道适配器-停止一个特定的并发使用者,spring-integration,Spring Integration,我使用spring集成组件连接我的流程 <bean id="myListener" class="org.springframework.jms.listener.DefaultMessageListenerContainer"> <property name="destination" ref="requestQueue"/> <property name="concurrentConsumers" value="5"/> <p
<bean id="myListener" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="destination" ref="requestQueue"/>
<property name="concurrentConsumers" value="5"/>
<property name="maxConcurrentConsumers" value="10"/>
<property name="connectionFactory" ref="connectionFactory"/>
<property name="taskExecutor" ref="threadPoolTaskExecutor"/>
<property name="sessionTransacted" value="true"/>
</bean>
<bean id="threadPoolTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="10" />
<property name="maxPoolSize" value="50" />
<property name="queueCapacity" value="10" />
<property name="waitForTasksToCompleteOnShutdown" value="false"/>
</bean>
<!-- Channel where service activator drops message to -->
<si:channel id="jmsOutChannel" />
<!-- This bean code calls DB to get some data and build a report/-->
<bean id="simpleExecutor" class="com.poc.reports.executors.SimpleCode"/>
<!-- Initialize service activator -->
<si:service-activator id="activator" input-channel="jmsInChannel"
ref="simpleExecutor" method="execute" output-channel="jmsOutChannel">
</si:service-activator>
<!-- outbound adaptor for response Queue -->
<jms:outbound-channel-adapter id="jmsout"
channel="jmsOutChannel" destination="responseQueue" />
- 消息驱动通道适配器从weblogic队列中拾取消息
- 使用消息转换器并将消息丢弃到通道
<bean id="myListener" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="destination" ref="requestQueue"/>
<property name="concurrentConsumers" value="5"/>
<property name="maxConcurrentConsumers" value="10"/>
<property name="connectionFactory" ref="connectionFactory"/>
<property name="taskExecutor" ref="threadPoolTaskExecutor"/>
<property name="sessionTransacted" value="true"/>
</bean>
<bean id="threadPoolTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="10" />
<property name="maxPoolSize" value="50" />
<property name="queueCapacity" value="10" />
<property name="waitForTasksToCompleteOnShutdown" value="false"/>
</bean>
<!-- Channel where service activator drops message to -->
<si:channel id="jmsOutChannel" />
<!-- This bean code calls DB to get some data and build a report/-->
<bean id="simpleExecutor" class="com.poc.reports.executors.SimpleCode"/>
<!-- Initialize service activator -->
<si:service-activator id="activator" input-channel="jmsInChannel"
ref="simpleExecutor" method="execute" output-channel="jmsOutChannel">
</si:service-activator>
<!-- outbound adaptor for response Queue -->
<jms:outbound-channel-adapter id="jmsout"
channel="jmsOutChannel" destination="responseQueue" />
<bean id="myListener" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="destination" ref="requestQueue"/>
<property name="concurrentConsumers" value="5"/>
<property name="maxConcurrentConsumers" value="10"/>
<property name="connectionFactory" ref="connectionFactory"/>
<property name="taskExecutor" ref="threadPoolTaskExecutor"/>
<property name="sessionTransacted" value="true"/>
</bean>
<bean id="threadPoolTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="10" />
<property name="maxPoolSize" value="50" />
<property name="queueCapacity" value="10" />
<property name="waitForTasksToCompleteOnShutdown" value="false"/>
</bean>
<!-- Channel where service activator drops message to -->
<si:channel id="jmsOutChannel" />
<!-- This bean code calls DB to get some data and build a report/-->
<bean id="simpleExecutor" class="com.poc.reports.executors.SimpleCode"/>
<!-- Initialize service activator -->
<si:service-activator id="activator" input-channel="jmsInChannel"
ref="simpleExecutor" method="execute" output-channel="jmsOutChannel">
</si:service-activator>
<!-- outbound adaptor for response Queue -->
<jms:outbound-channel-adapter id="jmsout"
channel="jmsOutChannel" destination="responseQueue" />
<bean id="myListener" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="destination" ref="requestQueue"/>
<property name="concurrentConsumers" value="5"/>
<property name="maxConcurrentConsumers" value="10"/>
<property name="connectionFactory" ref="connectionFactory"/>
<property name="taskExecutor" ref="threadPoolTaskExecutor"/>
<property name="sessionTransacted" value="true"/>
</bean>
<bean id="threadPoolTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="10" />
<property name="maxPoolSize" value="50" />
<property name="queueCapacity" value="10" />
<property name="waitForTasksToCompleteOnShutdown" value="false"/>
</bean>
<!-- Channel where service activator drops message to -->
<si:channel id="jmsOutChannel" />
<!-- This bean code calls DB to get some data and build a report/-->
<bean id="simpleExecutor" class="com.poc.reports.executors.SimpleCode"/>
<!-- Initialize service activator -->
<si:service-activator id="activator" input-channel="jmsInChannel"
ref="simpleExecutor" method="execute" output-channel="jmsOutChannel">
</si:service-activator>
<!-- outbound adaptor for response Queue -->
<jms:outbound-channel-adapter id="jmsout"
channel="jmsOutChannel" destination="responseQueue" />
<bean id="myListener" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="destination" ref="requestQueue"/>
<property name="concurrentConsumers" value="5"/>
<property name="maxConcurrentConsumers" value="10"/>
<property name="connectionFactory" ref="connectionFactory"/>
<property name="taskExecutor" ref="threadPoolTaskExecutor"/>
<property name="sessionTransacted" value="true"/>
</bean>
<bean id="threadPoolTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="10" />
<property name="maxPoolSize" value="50" />
<property name="queueCapacity" value="10" />
<property name="waitForTasksToCompleteOnShutdown" value="false"/>
</bean>
<!-- Channel where service activator drops message to -->
<si:channel id="jmsOutChannel" />
<!-- This bean code calls DB to get some data and build a report/-->
<bean id="simpleExecutor" class="com.poc.reports.executors.SimpleCode"/>
<!-- Initialize service activator -->
<si:service-activator id="activator" input-channel="jmsInChannel"
ref="simpleExecutor" method="execute" output-channel="jmsOutChannel">
</si:service-activator>
<!-- outbound adaptor for response Queue -->
<jms:outbound-channel-adapter id="jmsout"
channel="jmsOutChannel" destination="responseQueue" />
我有什么选择
<bean id="myListener" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="destination" ref="requestQueue"/>
<property name="concurrentConsumers" value="5"/>
<property name="maxConcurrentConsumers" value="10"/>
<property name="connectionFactory" ref="connectionFactory"/>
<property name="taskExecutor" ref="threadPoolTaskExecutor"/>
<property name="sessionTransacted" value="true"/>
</bean>
<bean id="threadPoolTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="10" />
<property name="maxPoolSize" value="50" />
<property name="queueCapacity" value="10" />
<property name="waitForTasksToCompleteOnShutdown" value="false"/>
</bean>
<!-- Channel where service activator drops message to -->
<si:channel id="jmsOutChannel" />
<!-- This bean code calls DB to get some data and build a report/-->
<bean id="simpleExecutor" class="com.poc.reports.executors.SimpleCode"/>
<!-- Initialize service activator -->
<si:service-activator id="activator" input-channel="jmsInChannel"
ref="simpleExecutor" method="execute" output-channel="jmsOutChannel">
</si:service-activator>
<!-- outbound adaptor for response Queue -->
<jms:outbound-channel-adapter id="jmsout"
channel="jmsOutChannel" destination="responseQueue" />
- 我试过这些:
- 通过JMX公开了spring的消息驱动器通道适配器
- 在消息驱动通道适配器上使用了停止方法
- 这会阻止消息驱动的通道适配器拾取新消息,这是很好的
- 但不会阻止已拾取消息且当前正在处理的消费者
- 我怎样才能停止这个在我的pojo中花费太长时间的过程
<bean id="myListener" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="destination" ref="requestQueue"/>
<property name="concurrentConsumers" value="5"/>
<property name="maxConcurrentConsumers" value="10"/>
<property name="connectionFactory" ref="connectionFactory"/>
<property name="taskExecutor" ref="threadPoolTaskExecutor"/>
<property name="sessionTransacted" value="true"/>
</bean>
<bean id="threadPoolTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="10" />
<property name="maxPoolSize" value="50" />
<property name="queueCapacity" value="10" />
<property name="waitForTasksToCompleteOnShutdown" value="false"/>
</bean>
<!-- Channel where service activator drops message to -->
<si:channel id="jmsOutChannel" />
<!-- This bean code calls DB to get some data and build a report/-->
<bean id="simpleExecutor" class="com.poc.reports.executors.SimpleCode"/>
<!-- Initialize service activator -->
<si:service-activator id="activator" input-channel="jmsInChannel"
ref="simpleExecutor" method="execute" output-channel="jmsOutChannel">
</si:service-activator>
<!-- outbound adaptor for response Queue -->
<jms:outbound-channel-adapter id="jmsout"
channel="jmsOutChannel" destination="responseQueue" />
更新-2
<bean id="myListener" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="destination" ref="requestQueue"/>
<property name="concurrentConsumers" value="5"/>
<property name="maxConcurrentConsumers" value="10"/>
<property name="connectionFactory" ref="connectionFactory"/>
<property name="taskExecutor" ref="threadPoolTaskExecutor"/>
<property name="sessionTransacted" value="true"/>
</bean>
<bean id="threadPoolTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="10" />
<property name="maxPoolSize" value="50" />
<property name="queueCapacity" value="10" />
<property name="waitForTasksToCompleteOnShutdown" value="false"/>
</bean>
<!-- Channel where service activator drops message to -->
<si:channel id="jmsOutChannel" />
<!-- This bean code calls DB to get some data and build a report/-->
<bean id="simpleExecutor" class="com.poc.reports.executors.SimpleCode"/>
<!-- Initialize service activator -->
<si:service-activator id="activator" input-channel="jmsInChannel"
ref="simpleExecutor" method="execute" output-channel="jmsOutChannel">
</si:service-activator>
<!-- outbound adaptor for response Queue -->
<jms:outbound-channel-adapter id="jmsout"
channel="jmsOutChannel" destination="responseQueue" />
这是我的密码。
<bean id="myListener" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="destination" ref="requestQueue"/>
<property name="concurrentConsumers" value="5"/>
<property name="maxConcurrentConsumers" value="10"/>
<property name="connectionFactory" ref="connectionFactory"/>
<property name="taskExecutor" ref="threadPoolTaskExecutor"/>
<property name="sessionTransacted" value="true"/>
</bean>
<bean id="threadPoolTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="10" />
<property name="maxPoolSize" value="50" />
<property name="queueCapacity" value="10" />
<property name="waitForTasksToCompleteOnShutdown" value="false"/>
</bean>
<!-- Channel where service activator drops message to -->
<si:channel id="jmsOutChannel" />
<!-- This bean code calls DB to get some data and build a report/-->
<bean id="simpleExecutor" class="com.poc.reports.executors.SimpleCode"/>
<!-- Initialize service activator -->
<si:service-activator id="activator" input-channel="jmsInChannel"
ref="simpleExecutor" method="execute" output-channel="jmsOutChannel">
</si:service-activator>
<!-- outbound adaptor for response Queue -->
<jms:outbound-channel-adapter id="jmsout"
channel="jmsOutChannel" destination="responseQueue" />
- 我看到交易如你所说正在进行中
<bean id="myListener" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="destination" ref="requestQueue"/>
<property name="concurrentConsumers" value="5"/>
<property name="maxConcurrentConsumers" value="10"/>
<property name="connectionFactory" ref="connectionFactory"/>
<property name="taskExecutor" ref="threadPoolTaskExecutor"/>
<property name="sessionTransacted" value="true"/>
</bean>
<bean id="threadPoolTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="10" />
<property name="maxPoolSize" value="50" />
<property name="queueCapacity" value="10" />
<property name="waitForTasksToCompleteOnShutdown" value="false"/>
</bean>
<!-- Channel where service activator drops message to -->
<si:channel id="jmsOutChannel" />
<!-- This bean code calls DB to get some data and build a report/-->
<bean id="simpleExecutor" class="com.poc.reports.executors.SimpleCode"/>
<!-- Initialize service activator -->
<si:service-activator id="activator" input-channel="jmsInChannel"
ref="simpleExecutor" method="execute" output-channel="jmsOutChannel">
</si:service-activator>
<!-- outbound adaptor for response Queue -->
<jms:outbound-channel-adapter id="jmsout"
channel="jmsOutChannel" destination="responseQueue" />
<bean id="myListener" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="destination" ref="requestQueue"/>
<property name="concurrentConsumers" value="5"/>
<property name="maxConcurrentConsumers" value="10"/>
<property name="connectionFactory" ref="connectionFactory"/>
<property name="taskExecutor" ref="threadPoolTaskExecutor"/>
<property name="sessionTransacted" value="true"/>
</bean>
<bean id="threadPoolTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="10" />
<property name="maxPoolSize" value="50" />
<property name="queueCapacity" value="10" />
<property name="waitForTasksToCompleteOnShutdown" value="false"/>
</bean>
<!-- Channel where service activator drops message to -->
<si:channel id="jmsOutChannel" />
<!-- This bean code calls DB to get some data and build a report/-->
<bean id="simpleExecutor" class="com.poc.reports.executors.SimpleCode"/>
<!-- Initialize service activator -->
<si:service-activator id="activator" input-channel="jmsInChannel"
ref="simpleExecutor" method="execute" output-channel="jmsOutChannel">
</si:service-activator>
<!-- outbound adaptor for response Queue -->
<jms:outbound-channel-adapter id="jmsout"
channel="jmsOutChannel" destination="responseQueue" />
<bean id="myListener" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="destination" ref="requestQueue"/>
<property name="concurrentConsumers" value="5"/>
<property name="maxConcurrentConsumers" value="10"/>
<property name="connectionFactory" ref="connectionFactory"/>
<property name="taskExecutor" ref="threadPoolTaskExecutor"/>
<property name="sessionTransacted" value="true"/>
</bean>
<bean id="threadPoolTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="10" />
<property name="maxPoolSize" value="50" />
<property name="queueCapacity" value="10" />
<property name="waitForTasksToCompleteOnShutdown" value="false"/>
</bean>
<!-- Channel where service activator drops message to -->
<si:channel id="jmsOutChannel" />
<!-- This bean code calls DB to get some data and build a report/-->
<bean id="simpleExecutor" class="com.poc.reports.executors.SimpleCode"/>
<!-- Initialize service activator -->
<si:service-activator id="activator" input-channel="jmsInChannel"
ref="simpleExecutor" method="execute" output-channel="jmsOutChannel">
</si:service-activator>
<!-- outbound adaptor for response Queue -->
<jms:outbound-channel-adapter id="jmsout"
channel="jmsOutChannel" destination="responseQueue" />
更新-3 -当与适配器一起使用时,在executor服务中维护事务非常有效
<bean id="myListener" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="destination" ref="requestQueue"/>
<property name="concurrentConsumers" value="5"/>
<property name="maxConcurrentConsumers" value="10"/>
<property name="connectionFactory" ref="connectionFactory"/>
<property name="taskExecutor" ref="threadPoolTaskExecutor"/>
<property name="sessionTransacted" value="true"/>
</bean>
<bean id="threadPoolTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="10" />
<property name="maxPoolSize" value="50" />
<property name="queueCapacity" value="10" />
<property name="waitForTasksToCompleteOnShutdown" value="false"/>
</bean>
<!-- Channel where service activator drops message to -->
<si:channel id="jmsOutChannel" />
<!-- This bean code calls DB to get some data and build a report/-->
<bean id="simpleExecutor" class="com.poc.reports.executors.SimpleCode"/>
<!-- Initialize service activator -->
<si:service-activator id="activator" input-channel="jmsInChannel"
ref="simpleExecutor" method="execute" output-channel="jmsOutChannel">
</si:service-activator>
<!-- outbound adaptor for response Queue -->
<jms:outbound-channel-adapter id="jmsout"
channel="jmsOutChannel" destination="responseQueue" />
- 关于杀死特定线程,我向executor服务添加了一个名为interruptNamedThread(String threadName)的方法,并通过JMX公开了它李>
- 触发它并设置中断标志
- 我可以检查中断状态并通过返回来终止线程(因为我的测试代码在循环中运行,并且有机会检查中断状态)
<bean id="myListener" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="destination" ref="requestQueue"/>
<property name="concurrentConsumers" value="5"/>
<property name="maxConcurrentConsumers" value="10"/>
<property name="connectionFactory" ref="connectionFactory"/>
<property name="taskExecutor" ref="threadPoolTaskExecutor"/>
<property name="sessionTransacted" value="true"/>
</bean>
<bean id="threadPoolTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="10" />
<property name="maxPoolSize" value="50" />
<property name="queueCapacity" value="10" />
<property name="waitForTasksToCompleteOnShutdown" value="false"/>
</bean>
<!-- Channel where service activator drops message to -->
<si:channel id="jmsOutChannel" />
<!-- This bean code calls DB to get some data and build a report/-->
<bean id="simpleExecutor" class="com.poc.reports.executors.SimpleCode"/>
<!-- Initialize service activator -->
<si:service-activator id="activator" input-channel="jmsInChannel"
ref="simpleExecutor" method="execute" output-channel="jmsOutChannel">
</si:service-activator>
<!-- outbound adaptor for response Queue -->
<jms:outbound-channel-adapter id="jmsout"
channel="jmsOutChannel" destination="responseQueue" />
<bean id="myListener" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="destination" ref="requestQueue"/>
<property name="concurrentConsumers" value="5"/>
<property name="maxConcurrentConsumers" value="10"/>
<property name="connectionFactory" ref="connectionFactory"/>
<property name="taskExecutor" ref="threadPoolTaskExecutor"/>
<property name="sessionTransacted" value="true"/>
</bean>
<bean id="threadPoolTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="10" />
<property name="maxPoolSize" value="50" />
<property name="queueCapacity" value="10" />
<property name="waitForTasksToCompleteOnShutdown" value="false"/>
</bean>
<!-- Channel where service activator drops message to -->
<si:channel id="jmsOutChannel" />
<!-- This bean code calls DB to get some data and build a report/-->
<bean id="simpleExecutor" class="com.poc.reports.executors.SimpleCode"/>
<!-- Initialize service activator -->
<si:service-activator id="activator" input-channel="jmsInChannel"
ref="simpleExecutor" method="execute" output-channel="jmsOutChannel">
</si:service-activator>
<!-- outbound adaptor for response Queue -->
<jms:outbound-channel-adapter id="jmsout"
channel="jmsOutChannel" destination="responseQueue" />
<bean id="myListener" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="destination" ref="requestQueue"/>
<property name="concurrentConsumers" value="5"/>
<property name="maxConcurrentConsumers" value="10"/>
<property name="connectionFactory" ref="connectionFactory"/>
<property name="taskExecutor" ref="threadPoolTaskExecutor"/>
<property name="sessionTransacted" value="true"/>
</bean>
<bean id="threadPoolTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="10" />
<property name="maxPoolSize" value="50" />
<property name="queueCapacity" value="10" />
<property name="waitForTasksToCompleteOnShutdown" value="false"/>
</bean>
<!-- Channel where service activator drops message to -->
<si:channel id="jmsOutChannel" />
<!-- This bean code calls DB to get some data and build a report/-->
<bean id="simpleExecutor" class="com.poc.reports.executors.SimpleCode"/>
<!-- Initialize service activator -->
<si:service-activator id="activator" input-channel="jmsInChannel"
ref="simpleExecutor" method="execute" output-channel="jmsOutChannel">
</si:service-activator>
<!-- outbound adaptor for response Queue -->
<jms:outbound-channel-adapter id="jmsout"
channel="jmsOutChannel" destination="responseQueue" />
感谢您的建议。您可以插入一个
任务执行器
,并将其等待任务完成设置为false;这将导致调用时,它的shutdown()
方法调用底层ExecutorService
上的shutdownow()
(或注入ExecutorService
并直接调用其shutdownow()
方法)
<bean id="myListener" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="destination" ref="requestQueue"/>
<property name="concurrentConsumers" value="5"/>
<property name="maxConcurrentConsumers" value="10"/>
<property name="connectionFactory" ref="connectionFactory"/>
<property name="taskExecutor" ref="threadPoolTaskExecutor"/>
<property name="sessionTransacted" value="true"/>
</bean>
<bean id="threadPoolTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="10" />
<property name="maxPoolSize" value="50" />
<property name="queueCapacity" value="10" />
<property name="waitForTasksToCompleteOnShutdown" value="false"/>
</bean>
<!-- Channel where service activator drops message to -->
<si:channel id="jmsOutChannel" />
<!-- This bean code calls DB to get some data and build a report/-->
<bean id="simpleExecutor" class="com.poc.reports.executors.SimpleCode"/>
<!-- Initialize service activator -->
<si:service-activator id="activator" input-channel="jmsInChannel"
ref="simpleExecutor" method="execute" output-channel="jmsOutChannel">
</si:service-activator>
<!-- outbound adaptor for response Queue -->
<jms:outbound-channel-adapter id="jmsout"
channel="jmsOutChannel" destination="responseQueue" />
这将取消(尝试中断)活动线程
<bean id="myListener" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="destination" ref="requestQueue"/>
<property name="concurrentConsumers" value="5"/>
<property name="maxConcurrentConsumers" value="10"/>
<property name="connectionFactory" ref="connectionFactory"/>
<property name="taskExecutor" ref="threadPoolTaskExecutor"/>
<property name="sessionTransacted" value="true"/>
</bean>
<bean id="threadPoolTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="10" />
<property name="maxPoolSize" value="50" />
<property name="queueCapacity" value="10" />
<property name="waitForTasksToCompleteOnShutdown" value="false"/>
</bean>
<!-- Channel where service activator drops message to -->
<si:channel id="jmsOutChannel" />
<!-- This bean code calls DB to get some data and build a report/-->
<bean id="simpleExecutor" class="com.poc.reports.executors.SimpleCode"/>
<!-- Initialize service activator -->
<si:service-activator id="activator" input-channel="jmsInChannel"
ref="simpleExecutor" method="execute" output-channel="jmsOutChannel">
</si:service-activator>
<!-- outbound adaptor for response Queue -->
<jms:outbound-channel-adapter id="jmsout"
channel="jmsOutChannel" destination="responseQueue" />
但是,如果您的服务正在做一些不可中断的事情,例如
<bean id="myListener" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="destination" ref="requestQueue"/>
<property name="concurrentConsumers" value="5"/>
<property name="maxConcurrentConsumers" value="10"/>
<property name="connectionFactory" ref="connectionFactory"/>
<property name="taskExecutor" ref="threadPoolTaskExecutor"/>
<property name="sessionTransacted" value="true"/>
</bean>
<bean id="threadPoolTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="10" />
<property name="maxPoolSize" value="50" />
<property name="queueCapacity" value="10" />
<property name="waitForTasksToCompleteOnShutdown" value="false"/>
</bean>
<!-- Channel where service activator drops message to -->
<si:channel id="jmsOutChannel" />
<!-- This bean code calls DB to get some data and build a report/-->
<bean id="simpleExecutor" class="com.poc.reports.executors.SimpleCode"/>
<!-- Initialize service activator -->
<si:service-activator id="activator" input-channel="jmsInChannel"
ref="simpleExecutor" method="execute" output-channel="jmsOutChannel">
</si:service-activator>
<!-- outbound adaptor for response Queue -->
<jms:outbound-channel-adapter id="jmsout"
channel="jmsOutChannel" destination="responseQueue" />
synchronize(foo) {}
lock.lock()
…或从插座读取数据等。感谢您的快速支持。我在这里看到了两个问题。1.)ExecutorService正在关闭所有活动线程。我只需要关闭有问题的线程。2.)一旦jms事务模式使用executor服务生成线程,我就会丢失它。如果executorservice派生线程中存在错误,我希望看到它回滚消息。您在哪里注入executorservice
?您是否要将其添加到频道?在侦听器容器上使用外部执行器(在适配器内,通过task executor
属性)不会影响事务语义。如果只想杀死选定的线程,则需要实现自己的看门狗代码。可能是一个通道拦截器,它在preSend()
中调度Thread.interrupt()
,并在postSend()
中取消调度的任务。只需添加我的问题和代码详细信息。您可以回顾一下吗?只有一个执行器,您看到的是该执行器创建的线程(它们有名称-n
)。感谢您的输入。在我的问题中添加了更新-3。请给我一些建议。
<bean id="myListener" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="destination" ref="requestQueue"/>
<property name="concurrentConsumers" value="5"/>
<property name="maxConcurrentConsumers" value="10"/>
<property name="connectionFactory" ref="connectionFactory"/>
<property name="taskExecutor" ref="threadPoolTaskExecutor"/>
<property name="sessionTransacted" value="true"/>
</bean>
<bean id="threadPoolTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="10" />
<property name="maxPoolSize" value="50" />
<property name="queueCapacity" value="10" />
<property name="waitForTasksToCompleteOnShutdown" value="false"/>
</bean>
<!-- Channel where service activator drops message to -->
<si:channel id="jmsOutChannel" />
<!-- This bean code calls DB to get some data and build a report/-->
<bean id="simpleExecutor" class="com.poc.reports.executors.SimpleCode"/>
<!-- Initialize service activator -->
<si:service-activator id="activator" input-channel="jmsInChannel"
ref="simpleExecutor" method="execute" output-channel="jmsOutChannel">
</si:service-activator>
<!-- outbound adaptor for response Queue -->
<jms:outbound-channel-adapter id="jmsout"
channel="jmsOutChannel" destination="responseQueue" />