dromara / forest

A high-level and lightweight declarative HTTP client framework for Java. it makes sending HTTP requests in Java easier.
MIT License
1.69k stars 217 forks source link

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

Open twtiyb opened 10 months ago

twtiyb commented 10 months ago

版本: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 commented 7 months ago

因为有缓存