使用quartz做集群任务的时候,在本地和测试环境正常,部署上线的时候, 启动异常:org.quartz.SchedulerException: Couldn't get host name!
这个是org.quartz.simpl.SimpleInstanceIdGenerator 中获取主机名异常了
public class SimpleInstanceIdGenerator implements InstanceIdGenerator {
public String generateInstanceId() throws SchedulerException {
try {
return InetAddress.getLocalHost().getHostName() + System.currentTimeMillis();
} catch (Exception e) {
throw new SchedulerException("Couldn't get host name!", e);
}
}
}
处理方法:
进入线上环境(centOs6.x):
1, 查看主机名(命令) : hostname
2, 打开hosts文件: vi /etc/hosts 查看是否有乱码等异常内容
3, 确保有: 127.0.0.1 后跟上面用hostname命令查看到的主机名, 如果没有则加上
如 : hostname -> USER-1234
则: 127.0.0.1 USER-1234
程序正常, 定时任务正常
谢谢