In groovy, is there a way to send a request to a URL, ignoring the response? The main aim is to send more requests to the server, in a shorter period of time.
As the result is unimportant to me, once the request is sent, I don’t want the script to wait for a response before continuing.
Here’s my current script:
(1..50).each { element->
def url = "http://someUrl"
url.toURL().text
}
In this code, the text method has to load the entire response, which I don’t really care about. The important part is that the request is sent, and waiting for a response is unimportant.
Is there a similar send method? (along the lines of..
url.toURL().send
Alternatively, is there a “groovy” way I can speed this up using GPARS to run the loop in parallel?
For just sending the URL, you could just use the
withInputStreamorwithReadermethods to send the request without reading the text. This will just create a handler to read the incoming text that would immediately close.As for GPars, you can just use a combination of
withPoolandcallAysncto create a thread pool to execute the requests concurrently. For example:However, if you’re not concerned with the number of threads, you could just create your own threads without GPars. For example: