THRIFT-2788: enable TCP keep alive for sockets in java lib.

This closes #248

Signed-off-by: Roger Meier <roger@apache.org>
diff --git a/lib/java/src/org/apache/thrift/transport/TNonblockingSocket.java b/lib/java/src/org/apache/thrift/transport/TNonblockingSocket.java
index 482bd14..23f8574 100644
--- a/lib/java/src/org/apache/thrift/transport/TNonblockingSocket.java
+++ b/lib/java/src/org/apache/thrift/transport/TNonblockingSocket.java
@@ -85,6 +85,7 @@
     Socket socket = socketChannel.socket();
     socket.setSoLinger(false, 0);
     socket.setTcpNoDelay(true);
+    socket.setKeepAlive(true);
     setTimeout(timeout);
   }
 
diff --git a/lib/java/src/org/apache/thrift/transport/TSocket.java b/lib/java/src/org/apache/thrift/transport/TSocket.java
index 606e8a9..c340dd2 100644
--- a/lib/java/src/org/apache/thrift/transport/TSocket.java
+++ b/lib/java/src/org/apache/thrift/transport/TSocket.java
@@ -68,6 +68,7 @@
     try {
       socket_.setSoLinger(false, 0);
       socket_.setTcpNoDelay(true);
+      socket_.setKeepAlive(true);
     } catch (SocketException sx) {
       LOGGER.warn("Could not configure socket.", sx);
     }
@@ -117,6 +118,7 @@
     try {
       socket_.setSoLinger(false, 0);
       socket_.setTcpNoDelay(true);
+      socket_.setKeepAlive(true);
       socket_.setSoTimeout(timeout_);
     } catch (SocketException sx) {
       LOGGER.error("Could not configure socket.", sx);