也许这是一个少见的情况,我使用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. [Doc]MongoDB用户创建与启用access-control

    文档链接:https://docs.mongodb.com/manual/tutorial/enable-authentication/ Pre 个人总感觉数据库的文档结构不太友好, 不太解决问题.以 ...

  2. Django——RESTful架构

    一.REST简述 来自维基百科的解释: 表现层状态转换(REST,英文:Representational State Transfer)是Roy Thomas Fielding博士于2000年在他的博 ...

  3. [POJ1220]NUMBER BASE CONVERSION (高精,进制转换)

    题意 任意进制之间的高进的转换 思路 相模倒排,高精处理 代码 我太弱了,下面附一个讨论里发的maigo思路的代码 ],A[]; ],d[]; main(){ for(scanf("%d&q ...

  4. HttpHandler和ashx使用Session 出现未初始化异常

    原因: HttpHandler和ashx要实现IRequiresSessionState接口才能访问Session信息 接口IRequiresSessionState: 指定目标 HTTP 处理程序需 ...

  5. vue2.0无限滚动加载数据插件

      做vue项目用到下拉滚动加载数据功能,由于选的UI库(element)没有这个组件,就用Vue-infinite-loading 这个插件代替,使用中遇到的一些问题及使用方法,总结作记录! 安装: ...

  6. 关于eclipse的Progress一直跳转的解决方案

    下载eclipse编程,发现了一个问题:执行main方法第二次console打印不出数据,后发现Progress一直跳转,而且非常多进度条在运行,关闭后第一次执行没问题,第二次问题重复出现. 有幸看到 ...

  7. python +selenium +chrome/firefox 环境配置

    http://ftp.mozilla.org/pub/firefox/releases/ 各firefox版本下载地址 http://ftp.mozilla.org/pub/firefox/relea ...

  8. page0902未完成

    /** * @author:(LiberHome) * @date:Created in 2019/3/1 23:14 * @description: * @version:$ */ import j ...

  9. map映射

    采集于:https://blog.csdn.net/luanpeng825485697/article/details/78056312 映射map: var map = new Map(); //映 ...

  10. 解析数学表达式 代码解析AST语法树

    2019年2月20日09:18:22 AST语法树自己写代码解析的话就比较麻烦,有现成的库可以解析PHP,就像webpack就是自己解析js的语法代码,编译成各种版本的可用代码 github http ...