中断MessageChannelPartitionHandler

时间:2016-01-27 23:06:13

标签: spring-integration spring-batch

我正在使用JmsOutboundGateway和MessageChannelPartitionHandler进行分区批处理作业。我希望能够在句柄方法

中中断此代码
Message<Collection<StepExecution>> message = messagingGateway.receive(replyChannel);

从另一个线程我试图在这个线程上调用interrupt()。添加此功能的最佳方法是什么?

澄清:

中断确实有效。但是,确实接收响应的每个分区的线程都有一个堆栈跟踪(如下所示)。这些线程仍然被阻塞,从而将它们从该线程池中拉出来,并且它们不可用于后续的分区作业。

            <b>Thread: springbatch.partitioned.jms.taskExecutor-1</b> :
        priority:5, demon:false, threadId:823, threadState:TIMED_WAITING<br />
        <blockquote>
            - waiting on <0xf483c36> (a
            java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)<br />sun.misc.Unsafe.park(Native
            Method)<br />java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:226)<br />
            java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2082)<br />
            java.util.concurrent.LinkedBlockingQueue.poll(LinkedBlockingQueue.java:467)<br />
            org.springframework.integration.jms.JmsOutboundGateway.obtainReplyFromContainer(JmsOutboundGateway.java:865)<br />
            org.springframework.integration.jms.JmsOutboundGateway.doSendAndReceiveAsync(JmsOutboundGateway.java:809)<br />
            org.springframework.integration.jms.JmsOutboundGateway.sendAndReceiveWithContainer(JmsOutboundGateway.java:649)<br />
            org.springframework.integration.jms.JmsOutboundGateway.handleRequestMessage(JmsOutboundGateway.java:580)<br />
            org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:134)<br />
            org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:73)<br />
            org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:115)<br />
            org.springframework.integration.dispatcher.UnicastingDispatcher.access$000(UnicastingDispatcher.java:52)<br />
            org.springframework.integration.dispatcher.UnicastingDispatcher$1.run(UnicastingDispatcher.java:97)<br />
            org.springframework.integration.util.ErrorHandlingTaskExecutor$1.run(ErrorHandlingTaskExecutor.java:52)<br />
            java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)<br />java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)<br />java.lang.Thread.run(Thread.java:744)<br />
            <br />

如何访问这些线程以进行中断?

1 个答案:

答案 0 :(得分:0)

中断线程会起作用;但是,中断被捕获(并且QueueChannel中的中断位重新设置)。

在此之后,收到的消息为空,因此分区处理程序将抛出MessageTimeoutException

目前无法确定超时是由于实际超时还是中断。