也许这是一个少见的情况,我使用HttpClient写了一个调用第三方服务的请求,在本机测试和腾讯云上测试都没有问题,但是放到阿里云之后,刚启动的时候是没有问题的,但是每次过零点之后,就会报异常:

java.net.UnknownHostException: www.xxxx.com: System error,异常栈如下:

java.net.UnknownHostException: wwww.xxx.com: System error
at java.base/java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
at java.base/java.net.InetAddress$PlatformNameService.lookupAllHostAddr(InetAddress.java:925)
at java.base/java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1505)
at java.base/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:844)
at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1495)
at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1354)
at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1288)
at org.apache.http.impl.conn.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:45)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:111)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)

只要重启一下java进程就好了。

在网上查找,说是jvm dns缓存导致的,在启动参数中添加下面两个参数:

设置解析成功的域名记录JVM中缓存的有效时间,这里修改为1秒钟有效,0表示禁止缓存,-1表示永远有效

-Dsun.net.inetaddr.ttl=1

设置解析失败的域名记录JVM中缓存的有效时间,这里修改为1秒钟有效,0表示禁止缓存,-1表示永远有效

-Dsun.net.inetaddr.negative.ttl=1

但是我设置了,貌似没有什么效果,有条件的同学可以试试。

最终没办法 ,使用Java jdk 自带的http服务重新写了一个请求,观察一段时间不再报那个异常,具体原因还是清楚,如果有知道的,谢谢告知。

package global.util;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
import org.apache.http.Header;
import global.common.log.DKLog; public class HttpUtil {
//发送https post请求
public static String sendHttpsPostRequest(String data, String requestUri, Header... headers) {
DataOutputStream wr = null;
BufferedReader in = null;
    HttpsUrlConnection con = null;
try {
URL obj = new URL(requestUri);
//https请求
con = (HttpsURLConnection) obj.openConnection();
if(headers != null) {
for(Header header : headers) {
con.setRequestProperty(header.getName(), header.getValue());
}
}
con.setRequestProperty("Content-Type", " application/json");
con.setConnectTimeout(15000);
// 添加请求头
con.setRequestMethod("POST");
// 发送Post请求
con.setDoOutput(true);
wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(data);
wr.flush();
int responseCode = con.getResponseCode();
if (responseCode == 200) {
in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
return response.toString();
} else {
DKLog.system.error("请求服务器异常,返回异常码:{}", responseCode);
}
} catch (Exception e) {
DKLog.system.error("Http请求失败,{},data:{}", requestUri, data, e);
} finally {
if (wr != null) {
try {
wr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
} }
if(con != null){
          con.disconnect();
}
}
return null;
} }

阿里云HttpClient跨天之后解析不了域名的更多相关文章

  1. 解决阿里云OSS跨域问题

    解决阿里云OSS跨域问题 现象 本人项目中对阿里云图片请求进行了两次,第一次通过img标签进行,第二次通过异步加载获取.第一次请求到图片,浏览器会进行缓存,随后再进行异步请求,保存跨域失效. 错误信息 ...

  2. 一个阿里云apache服务器配置两个或多个域名forLinux

    一个阿里云apache服务器配置两个或多个域名for Linux: 默认已经配置好了阿里云提供的一键web安装,可以参考:http://www.42iot.com/?id=8 修改/alidata/s ...

  3. 《阿里云天池大赛赛题解析》——O2O优惠卷预测

    赛事链接:https://tianchi.aliyun.com/competition/entrance/231593/introduction?spm=5176.12281925.0.0.7e157 ...

  4. 阿里云首次安装和部署nginx

    1.执行yum命令安装依赖 yum -y install pcre* yum -y install openssl* 2.下载nginx //如果没有安装wget,下载已编译版本 yum instal ...

  5. 干货满满!解密阿里云RPA (机器人流程自动化)的产品架构和商业化发展

    阿里云RPA,作为阿里云自研8年的技术,在资本的热捧下,逐渐从幕后来到台前,成为企业服务市场的黑马.本文将从产品上全面剖析,阿里云RPA这款产品的现阶段情况,同时简单谈谈阿里云RPA的商业化进展. 阿 ...

  6. 阿里云+wordpress搭建个人博客网站【小白专用的图文教程】

    [声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...

  7. 阿里云+wordpress搭建个人博客网站

    [正文] 在阿里云上搭建使用个人博客主要分为以下几个步骤: 1.购买阿里云ECS主机 2.购买域名 3.申请备案 4.环境配置 5.安装wordpress 6.域名解析 声明一下,本人对服务器端的知识 ...

  8. 阿里云+wordpress

    阿里云+wordpress搭建个人博客网站[小白专用的图文教程]   [声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源 ...

  9. 开通阿里云 CDN

    CDN,内容分发网络,主要功能是在不同的地点缓存内容,通过负载均衡技术,将用户的请求定向到最合适的缓存服务器上去获取内容,从而加快文件加载速度. 阿里云提供了按量计费的CDN,开启十分方便,于是我在自 ...

随机推荐

  1. ORACLE11g 重装系统后根据dbf恢复数据库

    1.安装一个和原系统一致的oracle 环境,主要包括版本.数据名sid.实例名.路径和数据库编码一致 2.修改listener.ora的参数 SID_LIST_LISTENER = (SID_LIS ...

  2. js估算一篇文章的阅读时长

    每天早上上班在地铁里我都有看技术类文章以及实时新闻的习惯,偶尔会看到有些文章的开始部分会提醒我们这篇文章大概的阅读时长,我就在想这是怎么实现的,具体到前端开发中,又是如何实现的.今天在浏览Segmen ...

  3. 编写程序,将来自文件中的行保存在一个vector<string>,然后使用一个istringstream 从vector中读取数据,每次读一个单词

    #include<fstream> #include <vector> #include<string> #include<iostream> #inc ...

  4. CSS3_线性渐变_径向渐变----背景

    渐变的本质: 绘制一张背景图片,所以使用 background 或者 background-image background 的诸多属性,渐变都是可以使用的(repeat,position) 百分比: ...

  5. poj1207 3n+1 problem

    The 3n + 1 problem Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 60496   Accepted: 19 ...

  6. 邮件服务器安装--Postfix + Dovecot + Squirrelmail--CentOS 6.4

    英文原文链接 : http://www.unixmen.com/install-postfix-mail-server-with-dovecot-and-squirrelmail-on-centos- ...

  7. qs.stringify和JSON.stringify()

    var a = {name:'hehe',age:10}; qs.stringify(a) // 'name=hehe&age=10' JSON.stringify(a) // '{" ...

  8. java-类、对象

    1.类和对象: 类是抽象的,通常不能直接使用 对象是具体的,根据类来创建对象. 2.如何定义一个类:成员变量.成员方法 成员变量:直接定义在类中,在方法外面 成员方法:去掉static 关键字,其他和 ...

  9. Mybatis+Mysql逆向工程

    目录结构: pom文件: <?xml version="1.0" encoding="UTF-8"?> <project xmlns=&quo ...

  10. linux基础命令--groupmod 修改组定义

    描述 groupmod命令用于修改系统上的组定义. groupmod命令通过更改组数据库(the group database)里的相关条目来修改指定的组. 语法 groupmod [选项] GROU ...