From 44370a42888541374c200c43450876be55add363 Mon Sep 17 00:00:00 2001 From: yangsen Date: Tue, 31 May 2022 22:40:45 +0800 Subject: [PATCH 1/2] handle dns thread pool --- .../java/com/qiniu/android/dns/dns/DnsResolver.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/library/src/main/java/com/qiniu/android/dns/dns/DnsResolver.java b/library/src/main/java/com/qiniu/android/dns/dns/DnsResolver.java index 1979595..9574255 100644 --- a/library/src/main/java/com/qiniu/android/dns/dns/DnsResolver.java +++ b/library/src/main/java/com/qiniu/android/dns/dns/DnsResolver.java @@ -11,12 +11,16 @@ import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; public abstract class DnsResolver implements IResolver { private static ScheduledExecutorService timeoutExecutorService = Executors.newSingleThreadScheduledExecutor(); + private static ExecutorService defaultExecutorService = new ThreadPoolExecutor(0, 4, + 60L, TimeUnit.SECONDS, new LinkedBlockingQueue()); private final int recordType; private final String[] servers; @@ -37,7 +41,7 @@ public DnsResolver(String server, int recordType, int timeout) { } public DnsResolver(String[] servers, int recordType, int timeout) { - this(servers, recordType, timeout, (servers != null && servers.length > 0) ? Executors.newFixedThreadPool(servers.length) : null); + this(servers, recordType, timeout, (servers != null && servers.length > 0) ? defaultExecutorService : null); } public DnsResolver(String[] servers, int recordType, int timeout, ExecutorService executorService) { @@ -140,7 +144,7 @@ public void run() { } if (exceptions[0] != null) { - throw exceptions[0]; + throw exceptions[0]; } return response[0]; @@ -148,5 +152,5 @@ public void run() { } - abstract DnsResponse request(String server, String host, int recordType) throws IOException; + abstract DnsResponse request(String server, String host, int recordType) throws IOException; } From 7d7e13c8e9c59947fe73aed3432a14fc36d9c3aa Mon Sep 17 00:00:00 2001 From: yangsen Date: Wed, 1 Jun 2022 12:23:09 +0800 Subject: [PATCH 2/2] change version --- CHANGELOG.md | 5 +++++ README.md | 2 +- library/src/main/java/com/qiniu/android/dns/Version.java | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8024611..e3ca466 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ #Changelog +## 1.0.1 (2022-06-02) + +### 修改 +* udp 和 doh resolver 共享 ThreadPool + ## 1.0.0 (2021-09-02) ### 增加 diff --git a/README.md b/README.md index 26c2c5e..b252d17 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ ### 通过maven * Android Studio中添加dependencies 或者 在项目中添加maven依赖 ``` -implementation 'com.qiniu:happy-dns:1.0.0' +implementation 'com.qiniu:happy-dns:1.0.1' ``` diff --git a/library/src/main/java/com/qiniu/android/dns/Version.java b/library/src/main/java/com/qiniu/android/dns/Version.java index b1ff24c..3d5163c 100644 --- a/library/src/main/java/com/qiniu/android/dns/Version.java +++ b/library/src/main/java/com/qiniu/android/dns/Version.java @@ -4,5 +4,5 @@ * Created by bailong on 15/6/12. */ public final class Version { - public static final String VERSION = "1.0.0"; + public static final String VERSION = "1.0.1"; }