Skip to content

Commit

Permalink
fix:线程统一
Browse files Browse the repository at this point in the history
  • Loading branch information
lemondark committed Sep 5, 2022
1 parent 682693f commit b32c2b1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/tencent/msdk/dns/DnsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ public static void init(Context context, /* @Nullable */DnsConfig config) {
ActivityLifecycleDetector.install(appContext);
// Room 本地数据读取
if (config.cachedIpEnable == true) {
new Thread(new Runnable() {
DnsExecutors.WORK.execute(new Runnable() {
@Override
public void run() {
Cache.readFromDb();
}
}).start();
});
}
// NOTE: 当前版本暂时不会提供为OneSdk版本, 默认使用灯塔上报
ReportManager.init(ReportManager.Channel.BEACON);
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/com/tencent/msdk/dns/core/ipRank/IpRankHelper.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.tencent.msdk.dns.core.ipRank;

import com.tencent.msdk.dns.DnsService;
import com.tencent.msdk.dns.base.log.DnsLog;
import com.tencent.msdk.dns.base.executor.DnsExecutors;
import com.tencent.msdk.dns.base.utils.IpValidator;
import com.tencent.msdk.dns.core.LookupResult;
import com.tencent.msdk.dns.core.rest.share.AbsRestDns;
Expand All @@ -18,8 +18,9 @@ public class IpRankHelper {

/**
* ipv4优选
* @param hostname -域名
* @param ips -解析的ip结果(含ipv4, ipv6)
*
* @param hostname -域名
* @param ips -解析的ip结果(含ipv4, ipv6)
* @param ipRankCallback -优选完成后的回调方法
*/
public void ipv4Rank(String hostname, String[] ips, final IpRankCallback ipRankCallback) {
Expand All @@ -45,21 +46,22 @@ public void ipv4Rank(String hostname, String[] ips, final IpRankCallback ipRankC

if (ipRankItem != null) {
// 发起IP测速线程任务
new Thread(new IpRankTask(hostname, ipv4Lists.toArray(new String[ipv4Lists.size()]), ipRankItem, new IpRankCallback() {
DnsExecutors.WORK.execute(new IpRankTask(hostname, ipv4Lists.toArray(new String[ipv4Lists.size()]), ipRankItem, new IpRankCallback() {
@Override
public void onResult(String hostname, String[] sortedIps) {
if (ipRankCallback != null) {
rankHosts.remove(hostname);
ipRankCallback.onResult(hostname, sortedIps);
}
}
})).start();
}));
}
}

/**
* 解析结果排序处理
* @param sortedIps -排序完的IP数组,当前主要对ipv4进行排序
* 解析结果排序处理
*
* @param sortedIps -排序完的IP数组,当前主要对ipv4进行排序
* @param lookupResult -域名缓存中的解析结果
* @return -测速后整理的解析结果
*/
Expand All @@ -81,6 +83,7 @@ public LookupResult sortResultByIps(String[] sortedIps, LookupResult lookupResul

/**
* 当前域名是否为优选配置项
*
* @param hostname -域名
* @return -IpRankItem
*/
Expand Down

0 comments on commit b32c2b1

Please sign in to comment.