我试图停止SqsMessageDrivenChannelAdapter
打电话stop()
时收到以下错误:
java.util.concurrent.TimeoutException: null
at java.util.concurrent.FutureTask.get(FutureTask.java:205)
at org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer.stop(SimpleMessageListenerContainer.java:197)
at org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer.doStop(SimpleMessageListenerContainer.java:133)
at org.springframework.cloud.aws.messaging.listener.AbstractMessageListenerContainer.stop(AbstractMessageListenerContainer.java:329)
at org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer.stop(SimpleMessageListenerContainer.java:1)
at org.springframework.integration.aws.inbound.SqsMessageDrivenChannelAdapter.doStop(SqsMessageDrivenChannelAdapter.java:140)
at org.springframework.integration.endpoint.AbstractEndpoint.stop(AbstractEndpoint.java:111)
我认为超时的第一个迹象还不够长,在查看问题后,我发现停止线程和正在运行的线程正在相互等待,并且TimeoutException
总会发生。我通过以下代码解决了这个问题:
new Thread() {
public void run()
{
sqsMessageRawDataChannelAdapter.stop();
LockSupport.parkNanos(TimeUnit.SECONDS.toNanos(5));
}
}.start();
我现在不再得到,TimeoutException
因为线程能够停止。我做错了什么,还是这是一个问题?