DataInputStream's read method takes time to read from the stream
hi,
i am facing an acute problem regarding the socket stream .
My program connects to a socketserver and sends request to the socketserver and based on the response string i do some database updation. this is quite simple task and previously it took about 1 second to process 10-15 records. But now the problem is that it is taking 5 to 6 secs to process a single record ! I have gone through the log files and found that the main problem is that it is taking time to read response from the socketserver. it is taking 5 to 6 secs to read response from the socketserver . the remaining part of the program is completing in miliseconds.Peviously it took 1 secs to read 10-15 response string from the socketserver.My program runs on 8 cpu unix machine. The socketserver sends response string with semicolon at the end of the string.
here is the sample response string :CCSCD1=CHG:ACK;
I have used the datainputstream to receive response from the socket server.I have used the read(byte[]a) method.
here is the code :
private String receiveResponse()
throws ErrorReadingToSocketException {
byte[] l_objReadBuffer =new byte[20];
String l_strOutputString = null;
int _iNoOfBytesReceived=0;
try {
writeLog(Level.INFO,"Before Reading from the input stream");
_iNoOfDataBytesReceived=_objDataInputStream.read(l_objReadBuffer);
writeLog(Level.INFO,"After Reading from the input stream");
l_strOutputString =new String (l_objReadBuffer);
System.out.println("Response :: "+l_strOutputString );
}
catch(java.net.SocketTimeoutException e) {
l_strOutputString = NACK_RESPONSE;
}
catch(IOException e) {
throw(new ErrorReadingToSocketException());
}
catch(Exception e){
writeLog(Level.SEVERE,"Exception Occured -->"+e.getMessage());
}
finally {
l_objReadBuffer = null;
}
return l_strOutputString;
}
THE FOLLOWING OBSERVATION FOUND IN THE LOG FILE:
2007-07-27 15:42:24.368:General.SuperClass:writeLog:Before Reading from the input stream
2007-07-27 15:42:30.219:General.SuperClass:writeLog:After Reading from the input stream
you can see that it is taking about 6 secs to read a single response from the stream.
The socket server program belongs to third party. So we cannot do much exercise on that.
an important thing to observe that at very first time whent it receive response from the stram it took about only few miliseconds to read,but afterwards it is taking time ,although the response string it reads first time is little different from the next responses.
first time response:ACK;
Message was edited by:
AbhijitRoy2005
Message was edited by:
AbhijitRoy2005

