Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用代理时,多线程并发问题 #170

Open
twtiyb opened this issue Nov 9, 2023 · 1 comment
Open

使用代理时,多线程并发问题 #170

twtiyb opened this issue Nov 9, 2023 · 1 comment

Comments

@twtiyb
Copy link

twtiyb commented Nov 9, 2023

版本:1.5.33
问题:多线程下,使用s5代理,发现返回的结果会串。比如5个不同的代理,结果是一样的。

代码:

@Test
void testS5Proxy() {
    ExecutorService executorService = ThreadUtil.newExecutor();
    List<AgProxy> list = AgProxy
            .findAll(Sort.descending("createTime"))
            .page(0, 100)
            .list();
    list.stream().forEach(agProxy -> {
        executorService.execute(() -> {
            validateS5(agProxy);
        });
    });
    try {
        executorService.awaitTermination(100, TimeUnit.MINUTES);
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
}

private void validateS5(AgProxy proxyParma) {
    ForestResponse forestResponse = Forest.get("http://ip-api.com/json")
            .proxy(ForestProxy.socks(proxyParma.getIp(), proxyParma.getPort()).username(proxyParma.getUsername()).password(proxyParma.getPassword()))
            .connectTimeout(15000)
            .sync()
            .maxRetryCount(1)
            .executeAsResponse();
    String resStr = forestResponse.get(String.class);
    log.info(resStr + proxyParma.toString());
}
@sunlikewang
Copy link

因为有缓存

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants