Connection pooling and Multithreading for TCP Socket?

孤街浪徒 提交于 2020-01-17 07:24:09

问题


I have a java application(say A) which communicate with an application(say B) via TCP Socket. My java application is multithreaded, can handle up to 100 threads. To communicate between A --> B we have 10 sockets.

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.

  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. Any examples.


回答1:


With Spring Integration:

  1. CachingClientConnectionFactory
  2. TcpOutboundGateway (with 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.




回答2:


I was able to resolve the problem stated in question via jPOS.

jPOS can do multiplexing. It uses ISOMessage field 11 and 41 for matching the request and response.

jPOS also providing pooling mechanism.



来源:https://stackoverflow.com/questions/43137948/connection-pooling-and-multithreading-for-tcp-socket

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!