dromara/forest

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

twtiyb opened this issue · 1 comments

twtiyb commented

版本: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());
}

因为有缓存