Kambiz
Kambiz

Reputation: 109

No persistant connection in TCP connection poll implemented by Apache Common Pool

How can I use Apache common pool to pool TCP connections and reuse the connection?

To implement a TCP connection pool, I am trying to use Apache common pool(1.6), I used the object pool that is posted in https://javaarchitectforum.com/tag/apache-common-object-pool-example/ to implement it.

I do expect to see persisted TCP connection upon initiating connection to another server and reuse it for other subsequent connection requests.

The issue is, I can not see any persistent connection to the server(netstat -an). By borrowing object, new connection is established and when return the object, socket is disconnected.No pooling!

Am I using correct approach to create TCP pool?

Upvotes: 2

Views: 329

Answers (1)

Kambiz
Kambiz

Reputation: 109

Issue is resolved.

Two amendments to resolve the issue:

  1. Upon returning object, the DataOutputStream should not to be closed.
  2. clientSocket should be kept alive upon makeObject() [clientSocket.setKeepAlive(true)].

As a result connections are persisted and reused for next requests.

Upvotes: 2

Related Questions