Skip to content

Commit

Permalink
Merge pull request #40 from YangSen-qn/master
Browse files Browse the repository at this point in the history
handle dns thread pool
  • Loading branch information
Mei-Zhao authored Jun 2, 2022
2 parents 1252ece + 7d7e13c commit 5bef59b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#Changelog
## 1.0.1 (2022-06-02)

### 修改
* udp 和 doh resolver 共享 ThreadPool

## 1.0.0 (2021-09-02)

### 增加
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
```


Expand Down
2 changes: 1 addition & 1 deletion library/src/main/java/com/qiniu/android/dns/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
10 changes: 7 additions & 3 deletions library/src/main/java/com/qiniu/android/dns/dns/DnsResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Runnable>());

private final int recordType;
private final String[] servers;
Expand All @@ -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) {
Expand Down Expand Up @@ -140,13 +144,13 @@ public void run() {
}

if (exceptions[0] != null) {
throw exceptions[0];
throw exceptions[0];
}

return response[0];
}

}

abstract DnsResponse request(String server, String host, int recordType) throws IOException;
abstract DnsResponse request(String server, String host, int recordType) throws IOException;
}

0 comments on commit 5bef59b

Please sign in to comment.