client.close(); is not closing connection to end point immediately. netstat is showing that the connection is open for couple of seconds after client.close call is completed. Is there a way to force close the connection immediately?
Asked
Active
Viewed 677 times
0
-
2I think Jersey client uses HttpURLConnection, and I think HttpURLConnection uses persistent connections by default. Have you tried `http.keepAlive=false`? – Brett Kail Nov 03 '16 at 19:30
1 Answers
-1
This probably is due to the settings of the SO_LINGER value that defines the time between the close()
call and the real closing of the connection.
More info about this socket option can be found in this SO answer, in Java it is possible to set the value with Socket.setSOLinger()
.
I don't know if it is possible to set this value for Jersey, at least I cannot find something in org.glassfish.jersey.client.ClientProperties

Community
- 1
- 1

P.J.Meisch
- 18,013
- 6
- 50
- 66
-
SO_LINGER does not 'define the time between the `close()` call and the real closing of the connection'. It defines the time spent *in* the `close()` call waitng for pending data to be flushed. It is is usually *off*, and as a matter of fact I have never seen production code where it was set to a positive value. The true explanation of this question is that given by @BrettKail: HTTP keepalive. – user207421 Nov 03 '16 at 20:11