Search code examples
androidhttpurlconnectionkeep-aliveokhttp

android is http.keepalive false necessary when using okhttp


I've recently taken over an Android project. We're looking to try to speed up a sync process we have. This is in the code currently:

System.setProperty("http.keepAlive", "false");

I didn't write the code, so I don't really know the reason this code was added, but ive done some googling and it seems necessary to keep connections working:

http://android-developers.blogspot.com/2011/09/androids-http-clients.html

HttpUrlConnection.openConnection fails second time

When we set this to true, the sync process speeds up substantially, but I don't want to set it to true and not have a decent idea of the consequences. Does anyone know if it's still necessary to set http.keepAlive to false? If so, for all Android devices? Is there an API level where it doesnt matter anymore?

Digging through the code history, we saw where http://square.github.io/okhttp/ was integrated. Is it still necessary to keep this setting to false when we're using OkHTTP?

Thanks!


Solution

  • You can change that to true with no problems. http.keepAlive just tells the client that it can keep the connection to the server open, rather than renegotiating a connection every time you do something. There shouldn't be any consequences to enabling it; at least, not in my experience.