Created
July 25, 2015 18:38
-
-
Save bdkosher/be3af24ba8d4e6d91be8 to your computer and use it in GitHub Desktop.
some code to test the execution of some code in a multi-threaded environment. Replace Thread.sleep with the actual web service all
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.concurrent.* | |
| def WEB_SERVICE_URL = new URL('http://localhost:8080/example/search?q=ornithology&rows=50') | |
| def THREADS = 3 | |
| def TASKS = THREADS * 4 | |
| def exec = { url -> | |
| def start = System.nanoTime() | |
| Thread.sleep(3000) // new JsonSlurper().parse(url) | |
| def end = System.nanoTime() | |
| println "${new Date().toString().split(/\s/)[3]} - ${Thread.currentThread().name} - Took ${(end - start) / 1e9} seconds to execute." | |
| } | |
| int i = 0 | |
| def service = Executors.newFixedThreadPool(THREADS, { r -> def t = new Thread(r); t.name = "Thread ${++i}"; t } as ThreadFactory) | |
| def tasks = (1..TASKS).collect { return { -> exec(WEB_SERVICE_URL) } as Callable } | |
| service.invokeAll(tasks) | |
| service.shutdown() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment