왜 Mac OS X Java가 Windows XP Java보다 5 배 이상 오래 걸리는지 알아 보도록 도와주세요.socket mac os x 대 windows java slow
Mac 및 PC Java에서 다르게 동작하는 코드가 있습니다. Windows XP 상자에서 여러 "서버"와 대화하는 Java GUI가 있습니다.
다른 Windows XP 시스템이나 Linux 컴퓨터에서 GUI를 실행하면 LabView가 메시지를 수신하고 1 초 이내에 응답합니다.
Mac OS X 상자에서 실행하면 5 초가 걸립니다. 멈춤은 "pot 7 \ r \ n"문자열과 LabView가 실제로 수신 한 시간 사이에 (모든 것을 통해 디버깅을 말할 수 있습니다.) 것 같습니다.
LabView는 Windows에서 들어오는 즉시 Pot 7 명령 (검사 할 디스플레이가 있음)을 봅니다. 그러나 LabView 프로그래머에 따르면 Mac OS에서 전송 될 때까지 5 초가 경과 할 때까지 명령이 화면에 표시되지 않습니다 기계.
더 많은 것을 알고있는 사람이 아하라고 말할 수있는 충분한 코드를 제공하려고 노력할 것입니다!
String IPaddress;
int commPort;
BufferedReader reader;
PrintWriter writer;
Socket sock;
long timeout = 8000;
...
public synchronized void connectCommPort() {
if (commportconnected != true) {
try {
sock = new Socket();
InetSocketAddress endpoint = new InetSocketAddress(IPaddress, commPort);
sock.connect(endpoint, timeout);
sock.setSoTimeout(timeout);
reader = new BufferedReader(new InputStreamReader(sock.getInputStream()));
writer = new PrintWriter(sock.getOutputStream());
commportconnected = true;
errorstatus = false;
} catch (IOException ex) {
logwriter("LabV: WARNING - network connection to Labview command port failed."+ex.toString());
commportconnected = false;
errorstatus = true;
}
}
}
... 맥 OS X 10.8에
public synchronized float[] readpots() {
String message = "pot 7";
connectCommPort();
if (commportconnected) {
try {
writer.print(message + "\r\n");
writer.flush();
logwriter("LabV: [sent] " + message);
shortpotvalues = potslistener();
} catch (Exception ex) {
}
disconnectCommPort();
}
potvalues[0] = shortpotvalues[0];
potvalues[1] = shortpotvalues[1];
potvalues[2] = shortpotvalues[2];
potvalues[3] = shortpotvalues[3];
potvalues[4] = shortpotvalues[4];
potvalues[5] = shortpotvalues[5];
potvalues[6] = shortpotvalues[6];
potvalues[7] = 5.0f;
return potvalues;
}
public synchronized float[] potslistener() {
String message = null;
int i = 0;
try {
//while ((message = reader.readLine()) != null && i < shortpotvalues.length) {
while (i < shortpotvalues.length) {
message = reader.readLine();
if (message != null)
{
logwriter("LabV: [received] " + message);
if (message.contains("."))
{
shortpotvalues[i] = Float.parseFloat(message);
i++;
}
}
else
{
logwriter("LabV: received NULL unexpectedly, may not have all pots correct");
}
} // close reader-ready-while
} catch (ArrayIndexOutOfBoundsException aiofbex) {
logwriter("LabV: in potslistener() Array out of bounds! " + aiofbex.toString());
} catch (Exception ex) {
logwriter("LabV: in potslistener() got exception: " + ex.toString());
}
return shortpotvalues;
}
. 자바 -version을 실행하는 제공 : 마지막으로 여기
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\gus>java -version
java version "1.7.0_07"
Java(TM) SE Runtime Environment (build 1.7.0_07-b10)
Java HotSpot(TM) Client VM (build 23.3-b01, mixed mode, sharing)
을에서 로그의 일부입니다
윈도우 XP (GUI를이 창에서 실행 잘 작동 할 때 사용되는 자바)에marks-Mac-mini:~ mark$ java -version
java version "1.6.0_43"
Java(TM) SE Runtime Environment (build 1.6.0_43-b01-447-11M4203)
Java HotSpot(TM) 64-Bit Server VM (build 20.14-b01-447, mixed mode)
주는 PC :
2013-03-19T11:45:22.000 LabV: [sent] pot 7
2013-03-19T11:45:22.921 LabV: [received] 2.310835
2013-03-19T11:45:22.921 LabV: [received] 2.447397
그리고 대응 맥 (송신 사이의 5 초에 유의하고 처음받은)에서 :
도움/조언을 미리 보내 주셔서 감사합니다.
후속은 :
난 이후이 같은 자바와 10.7.5 맥 OS 컴퓨터를 사용하는 경우 속도는 Windows XP와 동일한 것을 발견했습니다. 나는 현재 10.8.3 및 네트워킹 및 보안 방화벽 설정 문제를 조사하고있다. 다시 한번, 어떤 도움을 주셔서 감사합니다.
nagle 알고리즘을 비활성화하려고 할 수 있습니다. socket.setTcpNoDelay (true) –
감사합니다. 그러나 도움이되지 않았습니다. – evernoob
강제로 'flush()'를해도 PrintWriter *가 자동으로 플러시 *되어 문제가 될 수 있습니다. 'PrintWriter'보다는 스트림에 직접 쓰는 것이 좋습니다. 'socket.getOutputstream(). write ((message + "\ r \ n"). getBytes ("utf-8")); socket.getOutputstream(). flush(); ' –