Skip to content

Instantly share code, notes, and snippets.

@hisui
Created December 18, 2017 10:41
Show Gist options
  • Save hisui/e05ee6725df64097b7377000a9966983 to your computer and use it in GitHub Desktop.
Save hisui/e05ee6725df64097b7377000a9966983 to your computer and use it in GitHub Desktop.
def busyLoop(time: Int, threads: Int) = Action { implicit r =>
val started = System.currentTimeMillis()
val workers = (0 until threads).map { _ =>
val out = new Thread({ () =>
val digest = MessageDigest.getInstance("SHA-256")
while (started + time * 1000 >= System.currentTimeMillis()) {
digest.update(UUID.randomUUID().toString.getBytes(StandardCharsets.US_ASCII))
}
})
out.start()
out
}
var count = 0
while (workers.exists(_.isAlive)) {
count += 1
}
Ok(Json.obj("count" -> count))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment