开发者

Is there a "Socket Connection Pool" of sorts for Java EE apps?

开发者 https://www.devze.com 2022-12-21 14:59 出处:网络
I\'m writing a JAX-RS web service. It responds to client invocations by: Retrieving some info from a database

I'm writing a JAX-RS web service. It responds to client invocations by:

  1. Retrieving some info from a database
  2. Making a call to an external server

For 2) the server does not expose a web service interface (i.e. no WSDL interface or REST API). Instead, it uses a custom protocol over TCPIP. I'd like to make client calls from my JAX-RS resource directly to this server but I don't want to have to open a connection, authenticate, and close the connection for each call to my JAX-RS resource. Is there a way around this? In other words, is there something like a "socket connection pool" ava开发者_如何转开发ilable to Java EE apps? Would I have to use something like an ESB? Or is there an alternative that I'm overlooking?


The "right" way to do this would be to write a JCA connector for your external server. JCA is part of the Java EE stack, and is meant exactly for that: to provide inbound and outbound connectivity from the application server to external system. It supports pooling, authentication, transaction, etc. (Database and JMS broker are accesss through JCA connectors, btw).

Writing such an adapter can however be quite hard. Maybe investigate a lightweight approach which a generic pooling library (maybe you find something interesting in commons-pool, or c3p0) may be easier.

Have a look also at this answer about TCP connection pooling.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号