This discussion is archived
1 Reply Latest reply: Jun 15, 2012 9:51 AM by rukbat RSS

Slow response creating socket connections in Solaris with IP not available

944006 Newbie
Currently Being Moderated
Hello,

We are using 2 Solaris hosts and currently we are testing the response time when an standalone java application tries to connect to the second machine, and this one is not available. We have noticed that it takes several minutes to stop trying to connect to the remote machine:

java NewNormalSocketTest 10.25.13.244 1495
12:06:51:654
Socket Closed Statetrue
12:07:01:675

java NewSSLSocketTest 10.25.13.244 1496
12:14:26:995
Before Calling Socket Connect Call
Socket Closed Statetrue
socket closed successfully
From Socket Close12:14:37:449
From Exception:12:17:38:474

java NewNormalSocketTest 10.25.13.244 1497
12:21:35:308
Socket Closed Statetrue
12:21:45:320

java NewSSLSocketTest 10.25.13.244 1498
12:24:30:695
Before Calling Socket Connect Call
Socket Closed Statetrue
socket closed successfully
From Socket Close12:24:41:283
From Exception:12:27:42:307

Is this a known issue? What could be changed in the configuration to speed this up? The code we use is:

import javax.net.SocketFactory;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class NewNormalSocketTest
{
public static void main (String[] args)
{
final String ip=args[0];
final int port=Integer.parseInt(args[1]);
final Timer timer=new Timer();
final SimpleDateFormat dateFromat=new SimpleDateFormat("HH:mm:ss:SS");
System.out.println(dateFromat.format(new Date()));
// Socket socket1=null;
try
{
final Socket socket1 = SocketFactory.getDefault().createSocket ();
timer.schedule (
new TimerTask()
{
@Override
public void run ()
{
if (!socket1.isConnected())
{
Thread.currentThread().interrupt();
try
{
socket1.close();
System.out.println("Socket Closed State" + socket1.isClosed());
System.out.println("socket closed successfully");
}
catch (Exception ee)
{
ee.printStackTrace();
}
System.out.println(dateFromat.format(new Date()));
}
}
},1000*10);
socket1.connect(
new InetSocketAddress(InetAddress.getByName(ip), port));
}
catch ( Exception e)
{
System.out.println(dateFromat.format(new Date()));
e.printStackTrace();

}
finally
{
timer.cancel();
Thread.interrupted();
}
}
}

---------------------------------------------


import javax.net.ssl.SSLSocketFactory;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class NewSSLSocketTest
{
public static void main (String[] args)
{
final String ip=args[0];
final int port=Integer.parseInt(args[1]);
final Timer timer=new Timer();
final SimpleDateFormat dateFromat=new SimpleDateFormat("HH:mm:ss:SS");
System.out.println(dateFromat.format(new Date()));
// Socket socket1=null;
try
{
final Socket socket1 = SSLSocketFactory.getDefault().createSocket ();
timer.schedule (
new TimerTask()
{
@Override
public void run ()
{
if (!socket1.isConnected())
{
Thread.currentThread().interrupt();
try
{
socket1.close();
System.out.println("Socket Closed State" + socket1.isClosed());
System.out.println("socket closed successfully");
}
catch (Exception ee)
{
ee.printStackTrace();
}
System.out.println("From Socket Close"+dateFromat.format(new Date()));
}
}
},1000*10);
System.out.println("Before Calling Socket Connect Call");
socket1.connect(
new InetSocketAddress(InetAddress.getByName(ip), port));
System.out.println("After Calling Socket Connect Call Successfully");
}
catch ( Exception e)
{
System.out.println("From Exception:"+dateFromat.format(new Date()));
e.printStackTrace();

}
finally
{
timer.cancel();
Thread.interrupted();
}
}
}

Thanks in advance

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points