0
이 작은 스크립트를 ping google.pt에 작성하고 ping 결과로 무언가를하십시오. 문제는 내가 스크립트를 잠시 실행 시키면 더 많은 RAM을 사용한다는 것입니다.메모리 누수 문제를 해결하려면 어떻게해야합니까?
실수를 찾을 수없는 것 같습니다. 도와 주실 수 있습니까?
public static void main(String[] args) {
String ip = "google.pt -t -4";
int pingRetrieved = 0;
//window that displays the ping
s = new Square();
String pingCmd = "ping " + ip;
try {
Runtime r = Runtime.getRuntime();
Process p = r.exec(pingCmd);
BufferedReader in = new BufferedReader(new
InputStreamReader(p.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
//System.out.println(inputLine);
pingRetrieved = getPingValueFromPingResult(inputLine);
takeActionFromPingValue(pingRetrieved);
}
in.close();
} catch (IOException e) {
System.out.println(e);
}
}
편집 : getPingValue 방법 :
이public void printNumber(int ping){
this.getContentPane().removeAll();
JLabel jl = new JLabel();
Font f;
if(ping == 0){
this.setLocation((int) (Toolkit.getDefaultToolkit().getScreenSize().getWidth()-200), 0);
jl = new JLabel("Connection Error");
f = new Font("Fixedsys", Font.PLAIN, 25);
}else{
this.setLocation((int) (Toolkit.getDefaultToolkit().getScreenSize().getWidth()-100), 0);
jl = new JLabel(ping+"ms");
f = new Font("Fixedsys", Font.PLAIN, 25);
}
jl.setFont(f);
jl.setForeground(Color.MAGENTA);
this.getContentPane().add(jl, java.awt.BorderLayout.NORTH);
this.pack();
}
'takeActionFromPingValue'에는 무엇이 포함되어 있습니까? – Enzokie
다른 메소드는'getPingValueFromPingResult'와'takeActionFromPingValue'을 어떻게합니까? –
여기에 게시 된 코드 부분에는 명백한 문제가 없습니다. 누락 된 방법 일 가능성이 큽니다. – f1sh