Skip to content

Commit 6892606

Browse files
author
YangSen-qn
committed
optimize system dns
1 parent 1a0665c commit 6892606

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

.idea/modules.xml

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

library/src/main/java/com/qiniu/android/http/dns/SystemDns.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
public class SystemDns implements Dns {
1919

2020
private int timeout = 10;
21+
private final ExecutorService executor = new ThreadPoolExecutor(1, 2,
22+
60L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
2123

2224
public SystemDns() {
2325
}
@@ -31,14 +33,12 @@ public List<InetAddress> lookupInetAddress(final String hostname) throws Unknown
3133
throw new UnknownHostException("hostname is null");
3234
} else {
3335
try {
34-
FutureTask<List<InetAddress>> task = new FutureTask<>(
35-
new Callable<List<InetAddress>>() {
36-
@Override
37-
public List<InetAddress> call() throws Exception {
38-
return Arrays.asList(InetAddress.getAllByName(hostname));
39-
}
40-
});
41-
new Thread(task).start();
36+
Future<List<InetAddress>> task = executor.submit(new Callable<List<InetAddress>>() {
37+
@Override
38+
public List<InetAddress> call() throws Exception {
39+
return Arrays.asList(InetAddress.getAllByName(hostname));
40+
}
41+
});
4242
return task.get(timeout, TimeUnit.SECONDS);
4343
} catch (Exception var4) {
4444
UnknownHostException unknownHostException =

0 commit comments

Comments
 (0)