Skip to content

Commit

Permalink
Merge pull request #484 from YangSen-qn/develop
Browse files Browse the repository at this point in the history
handle dns thread poo
  • Loading branch information
Mei-Zhao authored Jun 2, 2022
2 parents 6fce0a6 + be3f3c0 commit 98d26ee
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 15 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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时生效)
```
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
Expand Down
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
12 changes: 12 additions & 0 deletions library/src/main/java/com/qiniu/android/http/dns/BaseDns.java
Original file line number Diff line number Diff line change
@@ -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<Runnable>());
}
10 changes: 7 additions & 3 deletions library/src/main/java/com/qiniu/android/http/dns/HttpDns.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,25 @@
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 {
public class HttpDns extends BaseDns implements Dns {

private IResolver httpIpv4Resolver;
private IResolver httpIpv6Resolver;

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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(1, 3,
60L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
public class SystemDns extends BaseDns implements Dns {

public SystemDns() {
}
Expand Down
10 changes: 7 additions & 3 deletions library/src/main/java/com/qiniu/android/http/dns/UdpDns.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@
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 {
public class UdpDns extends BaseDns implements Dns {
private IResolver udpIpv4Resolver;
private IResolver udpIpv6Resolver;

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);
}
}

Expand Down

0 comments on commit 98d26ee

Please sign in to comment.