From 5e03fbff12f235bf0697150daf2a3f4fd7123308 Mon Sep 17 00:00:00 2001 From: yangsen Date: Tue, 31 May 2022 22:17:26 +0800 Subject: [PATCH 1/4] handle dns thread pool --- .../main/java/com/qiniu/android/http/dns/HttpDns.java | 11 +++++++++-- .../java/com/qiniu/android/http/dns/SystemDns.java | 2 +- .../main/java/com/qiniu/android/http/dns/UdpDns.java | 11 +++++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/library/src/main/java/com/qiniu/android/http/dns/HttpDns.java b/library/src/main/java/com/qiniu/android/http/dns/HttpDns.java index 495d3a70..491e2f49 100644 --- a/library/src/main/java/com/qiniu/android/http/dns/HttpDns.java +++ b/library/src/main/java/com/qiniu/android/http/dns/HttpDns.java @@ -10,21 +10,28 @@ import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; public class HttpDns implements Dns { private IResolver httpIpv4Resolver; private IResolver httpIpv6Resolver; + private static final ExecutorService executor = new ThreadPoolExecutor(0, 4, + 60L, TimeUnit.SECONDS, new LinkedBlockingQueue()); + public HttpDns(int timeout) { String[] dohIpv4Servers = GlobalConfiguration.getInstance().getDohIpv4Servers(); if (dohIpv4Servers != null && dohIpv4Servers.length > 0) { - httpIpv4Resolver = new DohResolver(dohIpv4Servers, Record.TYPE_A, timeout); + httpIpv4Resolver = new DohResolver(dohIpv4Servers, Record.TYPE_A, timeout, executor); } String[] dohIpv6Servers = GlobalConfiguration.getInstance().getDohIpv6Servers(); if (dohIpv6Servers != null && dohIpv6Servers.length > 0) { - httpIpv6Resolver = new DohResolver(dohIpv6Servers, Record.TYPE_A, timeout); + httpIpv6Resolver = new DohResolver(dohIpv6Servers, Record.TYPE_A, timeout, executor); } } diff --git a/library/src/main/java/com/qiniu/android/http/dns/SystemDns.java b/library/src/main/java/com/qiniu/android/http/dns/SystemDns.java index e6037ae6..0dbcebd3 100644 --- a/library/src/main/java/com/qiniu/android/http/dns/SystemDns.java +++ b/library/src/main/java/com/qiniu/android/http/dns/SystemDns.java @@ -22,7 +22,7 @@ public class SystemDns implements Dns { private int timeout = 10; - private static final ExecutorService executor = new ThreadPoolExecutor(1, 3, + private static final ExecutorService executor = new ThreadPoolExecutor(0, 4, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue()); public SystemDns() { diff --git a/library/src/main/java/com/qiniu/android/http/dns/UdpDns.java b/library/src/main/java/com/qiniu/android/http/dns/UdpDns.java index 845776e2..ba183181 100644 --- a/library/src/main/java/com/qiniu/android/http/dns/UdpDns.java +++ b/library/src/main/java/com/qiniu/android/http/dns/UdpDns.java @@ -10,20 +10,27 @@ import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; public class UdpDns implements Dns { private IResolver udpIpv4Resolver; private IResolver udpIpv6Resolver; + private static final ExecutorService executor = new ThreadPoolExecutor(0, 4, + 60L, TimeUnit.SECONDS, new LinkedBlockingQueue()); + public UdpDns(int timeout) { String[] udpIpv4Servers = GlobalConfiguration.getInstance().getUdpDnsIpv4Servers(); if (udpIpv4Servers != null && udpIpv4Servers.length > 0) { - udpIpv4Resolver = new DnsUdpResolver(udpIpv4Servers, Record.TYPE_A, timeout); + udpIpv4Resolver = new DnsUdpResolver(udpIpv4Servers, Record.TYPE_A, timeout, executor); } String[] udpIpv6Servers = GlobalConfiguration.getInstance().getUdpDnsIpv6Servers(); if (udpIpv6Servers != null && udpIpv6Servers.length > 0) { - udpIpv6Resolver = new DnsUdpResolver(udpIpv6Servers, Record.TYPE_A, timeout); + udpIpv6Resolver = new DnsUdpResolver(udpIpv6Servers, Record.TYPE_A, timeout, executor); } } From 7e8ef63574786d9da769163cbb9fc1f43b41ba78 Mon Sep 17 00:00:00 2001 From: yangsen Date: Tue, 31 May 2022 23:04:55 +0800 Subject: [PATCH 2/4] change happy-dns dependencies --- library/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/build.gradle b/library/build.gradle index c8fdb533..307948af 100755 --- a/library/build.gradle +++ b/library/build.gradle @@ -54,7 +54,7 @@ dependencies { implementation 'com.squareup.okhttp3:okhttp:4.9.1' // implementation 'com.squareup.okhttp3:okhttp:3.12.+' - implementation 'com.qiniu:happy-dns:1.0.0' + implementation 'com.qiniu:happy-dns:1.0.+' // for javax.annotation.Nullable use in custom MultipartBody and Headers implements. // implementation 'com.google.code.findbugs:jsr305:3.0.2' implementation 'org.conscrypt:conscrypt-android:2.2.1' From 95a307ee1126d1adfffb4ec8c1e2c7faba453d4e Mon Sep 17 00:00:00 2001 From: yangsen Date: Tue, 31 May 2022 23:17:02 +0800 Subject: [PATCH 3/4] add BaseDns --- .../java/com/qiniu/android/http/dns/BaseDns.java | 12 ++++++++++++ .../java/com/qiniu/android/http/dns/HttpDns.java | 5 +---- .../java/com/qiniu/android/http/dns/SystemDns.java | 6 +----- .../main/java/com/qiniu/android/http/dns/UdpDns.java | 5 +---- 4 files changed, 15 insertions(+), 13 deletions(-) create mode 100644 library/src/main/java/com/qiniu/android/http/dns/BaseDns.java diff --git a/library/src/main/java/com/qiniu/android/http/dns/BaseDns.java b/library/src/main/java/com/qiniu/android/http/dns/BaseDns.java new file mode 100644 index 00000000..31c1f142 --- /dev/null +++ b/library/src/main/java/com/qiniu/android/http/dns/BaseDns.java @@ -0,0 +1,12 @@ +package com.qiniu.android.http.dns; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +class BaseDns { + int timeout = 10; + static final ExecutorService executor = new ThreadPoolExecutor(0, 4, + 60L, TimeUnit.SECONDS, new LinkedBlockingQueue()); +} diff --git a/library/src/main/java/com/qiniu/android/http/dns/HttpDns.java b/library/src/main/java/com/qiniu/android/http/dns/HttpDns.java index 491e2f49..a16de94f 100644 --- a/library/src/main/java/com/qiniu/android/http/dns/HttpDns.java +++ b/library/src/main/java/com/qiniu/android/http/dns/HttpDns.java @@ -15,14 +15,11 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; -public class HttpDns implements Dns { +public class HttpDns extends BaseDns implements Dns { private IResolver httpIpv4Resolver; private IResolver httpIpv6Resolver; - private static final ExecutorService executor = new ThreadPoolExecutor(0, 4, - 60L, TimeUnit.SECONDS, new LinkedBlockingQueue()); - public HttpDns(int timeout) { String[] dohIpv4Servers = GlobalConfiguration.getInstance().getDohIpv4Servers(); if (dohIpv4Servers != null && dohIpv4Servers.length > 0) { diff --git a/library/src/main/java/com/qiniu/android/http/dns/SystemDns.java b/library/src/main/java/com/qiniu/android/http/dns/SystemDns.java index 0dbcebd3..a89d0b29 100644 --- a/library/src/main/java/com/qiniu/android/http/dns/SystemDns.java +++ b/library/src/main/java/com/qiniu/android/http/dns/SystemDns.java @@ -19,11 +19,7 @@ /** * Created by yangsen on 2020/5/28 */ -public class SystemDns implements Dns { - - private int timeout = 10; - private static final ExecutorService executor = new ThreadPoolExecutor(0, 4, - 60L, TimeUnit.SECONDS, new LinkedBlockingQueue()); +public class SystemDns extends BaseDns implements Dns { public SystemDns() { } diff --git a/library/src/main/java/com/qiniu/android/http/dns/UdpDns.java b/library/src/main/java/com/qiniu/android/http/dns/UdpDns.java index ba183181..48d7ca0e 100644 --- a/library/src/main/java/com/qiniu/android/http/dns/UdpDns.java +++ b/library/src/main/java/com/qiniu/android/http/dns/UdpDns.java @@ -15,13 +15,10 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; -public class UdpDns implements Dns { +public class UdpDns extends BaseDns implements Dns { private IResolver udpIpv4Resolver; private IResolver udpIpv6Resolver; - private static final ExecutorService executor = new ThreadPoolExecutor(0, 4, - 60L, TimeUnit.SECONDS, new LinkedBlockingQueue()); - public UdpDns(int timeout) { String[] udpIpv4Servers = GlobalConfiguration.getInstance().getUdpDnsIpv4Servers(); if (udpIpv4Servers != null && udpIpv4Servers.length > 0) { From be3f3c0689a4a9eeb11fe0c64099f89e334c75eb Mon Sep 17 00:00:00 2001 From: yangsen Date: Wed, 1 Jun 2022 15:59:02 +0800 Subject: [PATCH 4/4] change version --- CHANGELOG.md | 4 +++- README.md | 2 +- library/build.gradle | 2 +- library/src/main/java/com/qiniu/android/common/Constants.java | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc41238e..b543833e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ #Changelog +## 8.4.4 (2022-06-02) +* 处理 Dns 预解析内存问题 -## 8.4.3 (2022-5-18) +## 8.4.3 (2022-05-18) * 修复:解决使用分片上传 v1 偶现上传异常:在多个区域域名之间进行上传重试的场景下空指针异常 * 补充了上传 response status code 注释,详情 [code 注释说明](https://github.com/qiniu/android-sdk/blob/master/library/src/main/java/com/qiniu/android/http/ResponseInfo.java) diff --git a/README.md b/README.md index 37630e32..6cc8ed69 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ https://github.com/qiniudemo/qiniu-lab-android | 7.0.7 | Android 2.2+ | android-async-http 1.4.8 | ### 注意 -* 推荐使用最新版:8.4.3 +* 推荐使用最新版:8.4.4 * 7.6.2 ~ 8.3.2 AndroidNetwork.getMobileDbm()可以获取手机信号强度,需要如下权限(API>=18时生效) ``` diff --git a/library/build.gradle b/library/build.gradle index 307948af..b7cf4061 100755 --- a/library/build.gradle +++ b/library/build.gradle @@ -54,7 +54,7 @@ dependencies { implementation 'com.squareup.okhttp3:okhttp:4.9.1' // implementation 'com.squareup.okhttp3:okhttp:3.12.+' - implementation 'com.qiniu:happy-dns:1.0.+' + implementation 'com.qiniu:happy-dns:1.0.1' // for javax.annotation.Nullable use in custom MultipartBody and Headers implements. // implementation 'com.google.code.findbugs:jsr305:3.0.2' implementation 'org.conscrypt:conscrypt-android:2.2.1' diff --git a/library/src/main/java/com/qiniu/android/common/Constants.java b/library/src/main/java/com/qiniu/android/common/Constants.java index 398aae48..61542ee8 100644 --- a/library/src/main/java/com/qiniu/android/common/Constants.java +++ b/library/src/main/java/com/qiniu/android/common/Constants.java @@ -3,7 +3,7 @@ public final class Constants { - public static final String VERSION = "8.4.3"; + public static final String VERSION = "8.4.4"; public static final String UTF_8 = "utf-8"; }