也许这是一个少见的情况,我使用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. 二分三元组 CodeForces - 251A

    题目链接: https://vjudge.net/problem/35188/origin 题目大意: 要求你找到一个 i < j < k时有 a[k]-a[i] <= d的组的个数 ...

  2. web.xml配置文件的简单说明

    简单说一下,web.xml的加载过程.当我们启动一个WEB项目容器时,容器包括(JBoss,Tomcat等).首先会去读取web.xml配置文件里的配置,当这一步骤没有出错并且完成之后,项目才能正常的 ...

  3. react-native添加react-native-vector-icons插件android遇到的问题

    问题 yarn add react-native-vector-icons后图省事使用react-native link来添加native配置,结果run时报错. ps:安装的需要native的插件不 ...

  4. CentOS7 64位安装mysql教程

    参考链接:http://baijiahao.baidu.com/s?id=1597184796823517712&wfr=spider&for=pc https://www.cnblo ...

  5. gitIgnore说明

    有些内容不需要提交到git服务器上,这时我们可以配置.gitIgnore文件.可参考:https://www.cnblogs.com/kevingrace/p/5690241.html 可能有时候你会 ...

  6. Notepad++ 64位 插件管理器 PluginManager 安装 更新

    32位的自带不多说,64位的内置不带,需要自己去找,这里给个地址: https://github.com/bruderstein/nppPluginManager/releases 地址里面有64位管 ...

  7. js 模拟超级大LE透中头奖 统计中头奖需要购买的彩票次数以及购买总金额

    <!DOCTYPE html> <html> <head> <title>超级大LE透模拟</title> </head> &l ...

  8. mysql-cluster集群配置

    环境: centos7:192.168.1.16,192.168.1.170 mysql-cluster-community-7.6.8-1.el7.x86_64.rpm-bundle.tar 安装: ...

  9. 用SharedPreference或文件的方式存储数据

    一.用SharedPreference存储数据 当程序有少量的数据需要保存,而这些数据的格式比较简单(例如一些配置信息),这个时候就可以使用SharedPreference来进行保存 下面例子将演示向 ...

  10. CSCI 1100 — Computer Science 1 Homework

    CSCI 1100 — Computer Science 1 Homework 8CS1 Multiverse: ClassesOverviewThis homework is worth 100 p ...