简体   繁体   English

TCP套接字的连接池和多线程?

[英]Connection pooling and Multithreading for TCP Socket?

I have a java application(say A) which communicate with an application(say B) via TCP Socket. 我有一个通过TCP套接字与应用程序(例如B)通信的Java应用程序(例如A)。 My java application is multithreaded, can handle up to 100 threads. 我的Java应用程序是多线程的,最多可以处理100个线程。 To communicate between A --> B we have 10 sockets. 为了在A-> B之间进行通信,我们有10个套接字。

Challenges - 挑战 -

  1. Connection Pooling - need connection pooling mechanism to handle n(say 100) number of thread(of application A), communicating to application B via x(say 10) number of TCP Socket. 连接池 -需要连接池机制来处理n个(例如100个)应用程序A线程,并通过x个(例如10个)TCP Socket与应用程序B通信。

  2. Multithreading - How can two thread access same socket send the request one by one and get back the response mapped to appropriate thread. 多线程 -两个线程如何访问同一套接字,一个接一个地发送请求并获取映射到适当线程的响应。

  3. Multiple request - Is it possible that two thread can send the request on single socket simultaneously . 多个请求 -两个线程是否可以同时在单个套接字上发送请求。

Can we over come this challenge via any framework? 我们可以通过任何框架克服这一挑战吗? Is it possible? 可能吗? I heard that Spring Integration/ApacheCamel/Local MQ can resolve this solutions. 我听说Spring Integration / ApacheCamel / Local MQ可以解决此解决方案。 Any examples. 任何例子。

With Spring Integration: 使用Spring Integration:

  1. CachingClientConnectionFactory
  2. TcpOutboundGateway (with CachingClientConnectionFactory ). TcpOutboundGateway (带有CachingClientConnectionFactory )。
  3. Collaborating Outbound and Inbound Channel Adapters . 协作出站和入站通道适配器

But you have to do your own request/reply collaboration (usually based on something in the message); 但是您必须进行自己的请求/回复协作(通常基于消息中的内容); the replies may not come back in the order they were sent. 回复可能不会按照发送顺序返回。 Since there is no standard way to perform that collaboration, the framework doesn't support it itself. 由于没有执行此协作的标准方法,因此该框架本身不支持它。

I was able to resolve the problem stated in question via jPOS. 我能够通过jPOS解决上述问题。

jPOS can do multiplexing. jPOS可以进行多路复用。 It uses ISOMessage field 11 and 41 for matching the request and response. 它使用ISOMessage字段11和41来匹配请求和响应。

jPOS also providing pooling mechanism. jPOS还提供池化机制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM