在 groovy 中列出多处理
List multiprocessing in groovy
我在 groovy 中有一个 URL 列表,我想为每个 URL 启动一个新线程。我想知道执行此列表多处理的 groovy 方法。
假设我有一个 url 列表,我希望同时从中获取数据。
def urls = ["https://stackexchange.com","https://amazon.com","https://bing.com","https://google.com"]
import groovyx.gpars.GParsPool
def urls = ["https://stackexchange.com","https://amazon.com","https://bing.com","https://google.com"]
GParsPool.withPool( urls.size() ) { urls.eachParallel { url ->
try {
// test if url is reachable
response = url.toURL().text
println url + " connected OK"
}
catch (Exception e) { println e }
}
}
我在 groovy 中有一个 URL 列表,我想为每个 URL 启动一个新线程。我想知道执行此列表多处理的 groovy 方法。 假设我有一个 url 列表,我希望同时从中获取数据。
def urls = ["https://stackexchange.com","https://amazon.com","https://bing.com","https://google.com"]
import groovyx.gpars.GParsPool
def urls = ["https://stackexchange.com","https://amazon.com","https://bing.com","https://google.com"]
GParsPool.withPool( urls.size() ) { urls.eachParallel { url ->
try {
// test if url is reachable
response = url.toURL().text
println url + " connected OK"
}
catch (Exception e) { println e }
}
}