向各位大侠请教:
怎么样能用java 实现高效率的ping网站内所有网点ip的功能,大约500多个ip,最好能给出完整代码:参数是ip,返回值是0:网络不通,1:通。
谢谢
------解决方案--------------------------------------------------------
- Java code
public int ping(String ip) { return InetAddress.getByName(host).isReachable(5000)?1:0;}String[] iparray = new String[500];//......for (int i=0; i<iparray.length; i++) { int result = ping(iparray[i]);}
------解决方案--------------------------------------------------------
- Java code
public int ping(String ip) { return InetAddress.getByName(ip).isReachable(5000)?1:0;}String[] iparray = new String[500];//......for (int i=0; i<iparray.length; i++) { int result = ping(iparray[i]);}
------解决方案--------------------------------------------------------
采用多线程:
- Java code
for (Integer i = 1; i <= station; i++) { String ip = pro.getPropertyValue("station" + i.toString(), "ip"); MonitorThread myThread = new MonitorThread(i, ip); threads[i] = new Thread(myThread); threads[i].start();}