private static class MonitoringThread implements Runnable {     
 private Logger log = Logger.getLogger(MonitoringThread.class);   
 
 private Socket socket;         
 private PrintWriter out;                
 public void run() {           
     
  int port = Integer.parseInt(MsgUtil.getConfig("port"));      
  try {                ServerSocket ss = new ServerSocket(port);  
  while (true) {                   

log.info("Cycle to monitor port " + port);                   

socket = ss.accept();                   

log.info("The socket is connected ..." + socket.hashCode());                   

String performanceData = PerformanceCollect.getPerformanceData();                   

log.debug(performanceData);                   

out = new PrintWriter(socket.getOutputStream(), true);                   

out.println(performanceData);                   

out.close();                  

  socket.close();                  

  log.info("The socket is closed ..." + socket.hashCode());               

}           

} catch (IOException e) {               

log.error("ListenPort io exception : " + e);          

  }      

  }   

}
 }
}
 

創作者介紹
創作者 shadow 的頭像
shadow

資訊園

shadow 發表在 痞客邦 留言(0) 人氣()