【问题标题】:Spring Integration : SimpleAsyncTaskExecutor春季集成:SimpleAsyncTaskExecutor
【发布时间】:2019-08-05 18:23:29
【问题描述】:

我在这个网站上阅读了另一个这样的问题,但我不知道如何解决这个问题。

Spring Integration: Application leaking SimpleAsyncTaskExecutor threads?

我的错误与上一个链接类似

SimpleAsyncTaskExecutor-2327" - Thread t@2405
java.lang.Thread.State: WAITING
    at sun.misc.Unsafe.park(Native Method)
    - parking to wait for <7a224c1> (a java.util.concurrent.CountDownLatch$Sync)
    at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:836)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(AbstractQueuedSynchronizer.java:997)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1304)
    at java.util.concurrent.CountDownLatch.await(CountDownLatch.java:231)
    at org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel.receive(GenericMessagingTemplate.java:199)
    at org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel.receive(GenericMessagingTemplate.java:192)
    at org.springframework.messaging.core.GenericMessagingTemplate.doReceive(GenericMessagingTemplate.java:130)
    at org.springframework.messaging.core.GenericMessagingTemplate.doSendAndReceive(GenericMessagingTemplate.java:157)
    at org.springframework.messaging.core.GenericMessagingTemplate.doSendAndReceive(GenericMessagingTemplate.java:45)
    at org.springframework.messaging.core.AbstractMessagingTemplate.sendAndReceive(AbstractMessagingTemplate.java:42)
    at org.springframework.integration.core.MessagingTemplate.sendAndReceive(MessagingTemplate.java:97)
    at org.springframework.integration.core.MessagingTemplate.sendAndReceive(MessagingTemplate.java:38)
    at org.springframework.messaging.core.AbstractMessagingTemplate.convertSendAndReceive(AbstractMessagingTemplate.java:79)
    at org.springframework.messaging.core.AbstractMessagingTemplate.convertSendAndReceive(AbstractMessagingTemplate.java:70)
    at org.springframework.integration.gateway.MessagingGatewaySupport.doSendAndReceive(MessagingGatewaySupport.java:449)

我正在使用

  • spring-integration-java-dsl-1.2.3.RELEASE
  • spring-integration-ip-4.3.17.RELEASE
  • spring-integration-http-4.3.17.RELEASE

我的场景是下一个:我通过 Api 控制器收到一条消息,这条消息通过一个非 TCP 套接字发送。

我已经定义了一个 MessageGateway 接口

@MessagingGateway(defaultRequestChannel = "toTcp.input")
public interface MessageTcpGateway {

@Gateway
public ListenableFuture<Void> sendTcpChannel(byte[] data, 
 @Header("connectionId") String connectionId );
}

在我在这样的服务类中使用这个接口之后:

public void sendMessageTcpGateway(final String bridgeId,final String connectionId, final byte[] message) {
    LOGGER.debug("sendMessageTcpGateway connectionId:{} - message:{}", connectionId, message);
    if (holder.existsConnection(connectionId)!=null) {
           gatewayTcp.sendTcpChannel(message,connectionId);
    } else {
        LOGGER.error("Not send message connectionId:{} - message:{}", connectionId, message);
    }
}
  1. 为什么线程在等待?我的进程是否在等待任何类型的迹象而我不被考虑?我猜如果连接不可用或出现任何错误,spring-integration 会抛出异常

  2. 我该如何解决这个问题?

【问题讨论】:

    标签: spring-integration spring-integration-dsl


    【解决方案1】:

    我想知道为什么不遵循该 SO 线程的建议... ListenableFuture&lt;Void&gt; 是您解决方案中的瓶颈。正如您通过堆栈跟踪看到的那样,您有 doSendAndReceive(),但我想您的目标解决方案确实是单向的,并且不会为标头中的 replyChannel 返回任何内容。

    您应该考虑只使用普通的 void 返回类型和 ExecutorChannel 下游。

    不幸的是,我们无法从框架端检测到这种情况,因为网关方法的Future 返回类型表明您将执行请求-回复异步方式。在您的情况下,它只是一个异步请求,仅此而已。

    【讨论】:

      猜你喜欢
      • 2017-07-28
      • 1970-01-01
      • 2022-10-14
      • 1970-01-01
      • 2015-06-18
      • 1970-01-01
      • 2020-12-06
      • 2010-12-05
      • 1970-01-01
      相关资源
      最近更新 更多