项目有个定时任务是根据主机名称来判断是否执行,原来一直运行良好,这两天突然出现了问题,后台日志报错如下:
2016-08-30 21:02:00,013 [eventScheduler-5] ERROR cn.xxx.man.task.event.EventTask – 获取主机名称发成错误:test.xxx.priv: test.xxx.priv: unknown error
Java代码大致如下:
public class InetAddressTest {
public static void main(String[] args) {
String address = “”;
try {
//System.out.println(“InetAddress.getLocalHost() ==> ” + InetAddress.getLocalHost());
//System.out.println(“InetAddress.getLocalHost().getHostName() ==> ” + InetAddress.getLocalHost().getHostName());
//System.out.println(“InetAddress.getLocalHost().getHostAddress() ” + InetAddress.getLocalHost().getHostAddress());
//System.out.println(“InetAddress.getLocalHost().getCanonicalHostName() ==> ” + InetAddress.getLocalHost().getCanonicalHostName());
address = InetAddress.getLocalHost().getHostName();
System.out.println(“address ==》 ” + address);
} catch (UnknownHostException e) {
System.out.println(“获取主机名称发成错误:” + e.getMessage().toString());
}
}
}
解决方案是修改/etc/hosts文件,添加一条
127.0.0.1 主机名
主机名是新加的,原来没有,保存,问题解决。
Sorry, the comment form is closed at this time.
No comments yet.