www.pudn.com > network-java.rar > IPSavingThread$.java
package netManager.discovery.pinger; /** *Title: IPSavingThread(已废弃)
*Description: 保存在线IP地址线程 * 通过JNI调用C++写的Ping.dll,测试该IP地址是否在线, * 如果在线则保存的数据库中。
*Copyright: Copyright (c) 2006
*Company:
* @author:谢飞 * @version 1.0 */ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class IPSavingThread extends Thread{ private int iden; //标识ID 1-该IP主机在线 0-不在线 private String HostIP; //测试IP private boolean runningFlag; private Log log = LogFactory.getLog("IPSavingThread"); public IPSavingThread(){ runningFlag = false; } public boolean isRunning(){ return runningFlag; } public synchronized void setRunning(boolean flag){ runningFlag = flag; if(runningFlag == true){ this.notify(); //唤醒线程 } } public void setHostIP(String HostIP){ this.HostIP = HostIP; } /* static String path = System.getProperty("user.dir"); static { System.load(path + "/ping"); //调用ping.dll执行ping } */ //private native int ping(String HostIP); public synchronized void run(){ //注意此方法必须同步 try{ while(true){ if(!runningFlag){ this.wait(); //线程启动后默认为睡眠 } else{ //iden = this.ping(HostIP); //System.out.println(iden); //lSystem.out.println(HostIP); log.error(HostIP); setRunning(false); } } } catch(Exception e){ e.printStackTrace(); log.error(e); } } }