dev-resources.site
for different kinds of informations.
Processing in parallel with Groovy
Published at
4/3/2023
Categories
groovy
Author
ou_ryperd
Categories
1 categories in total
groovy
open
Author
9 person written this
ou_ryperd
open
I had to place thousands of messages on a queue and collect each response by an ID. This is how I used multiprocessing to do that, so that messages were processed in parallel to make it complete faster:
//lists to keep the thread instances
List threads1 = []
List threads2 = []
//first task (e.g. putting on Q)
def doThis = { i, j ->
sleep(randNum(100))
println "doThis(${i}) thread: ${j}"
}
//second task (e.g. getting from Q)
def doThat = { i, j ->
sleep(randNum(20000))
println "doThat(${i}) thread: ${j}"
}
//call first task (e.g. for eachRow from DB, put msg on Q)
20.times { i ->
def t1
t1 = Thread.start { doThis(i, t1.name) }
threads1.add(t1)
}
//wait for all task 1 threads to end
for (thread in threads1) {
thread.join()
println "doThis joined: ${thread.name}"
}
//call second task (e.g. for each correlation ID, get msg from Q)
20.times { i ->
def t2
t2 = Thread.start { doThat(i, t2.name) }
threads2.add(t2)
}
//wait for all task 2 threads to end
for (thread in threads2) {
thread.join()
println "doThat joined: ${thread.name}"
}
println "All threads done"
def randNum(maxSize) { //create random wait times
return Math.abs(new Random().nextInt() % maxSize) + 1
}
groovy Article's
30 articles in total
Exploring Groovy: Features and Advantages Over Java
read article
Tasting Groogle
read article
Machine Learning with Spark and Groovy
read article
Groogle 4.0.0 (Google DSL)
read article
Tutorial: Learn how to use the H2 Database with Spring Boot! 🤔
read article
Mocking with Groovy
read article
Check for newer versions of dependencies in pom.xml
read article
Setting up linters in Gitlab CI for C++ and Groovy / Jenkins code
read article
Machine Learning con Groovy
read article
Groovy 🎷 Cheat Sheet - 01 Say "Hello" from Groovy
read article
Advice needed
read article
HackTheBox - Writeup Builder [Retired]
read article
The golden age of Kotlin and its uncertain future
read article
Probando a firmar documentos con Docuten
read article
Groogle al rescate
read article
Tech Watch #3 — October, 20, 2023
read article
Swagger-Operator, let groovy operate your cluster
read article
Nextflow: Organizando fotos por geoposicion
read article
🎶 Groovy: The Dynamic and Versatile JVM Language! 🚀
read article
FediSearch
read article
Introduction To Jenkins Shared Libraries
read article
Remove items matching a pattern from a list in Groovy
read article
Processing in parallel with Groovy
currently reading
Wednesday Links - Edition 2023-05-03 🇵🇱📜
read article
Wednesday Links - Edition 2023-04-26
read article
An Introduction to Jenkins Pipeline: Simplifying Continuous Integration and Delivery with Examples
read article
Graalvanizando un script de Groovy
read article
Passage of time calculations in Groovy
read article
Write a method like Python's string.printable in Groovy
read article
Neat time and date manipulation with Groovy
read article
Featured ones: