in quarkus-app/src/main/java/io/containerapps/javaruntime/workshop/quarkus/QuarkusResource.java [59:97]
public String cpu(@QueryParam("iterations") @DefaultValue("10") Long iterations,
@QueryParam("db") @DefaultValue("false") Boolean db,
@QueryParam("desc") String desc) {
LOGGER.log(INFO, "Quarkus: cpu: {0} {1} with desc {2}", iterations, db, desc);
Long iterationsDone = iterations;
Instant start = Instant.now();
if (iterations == null) {
iterations = 20000L;
} else {
iterations *= 20000;
}
// tag::adocAlgoCPU[]
while (iterations > 0) {
if (iterations % 20000 == 0) {
try {
Thread.sleep(20);
} catch (InterruptedException ie) {
}
}
iterations--;
}
// end::adocAlgoCPU[]
if (db) {
Statistics statistics = new Statistics();
statistics.type = Type.CPU;
statistics.parameter = iterations.toString();
statistics.duration = Duration.between(start, Instant.now());
statistics.description = desc;
repository.persist(statistics);
}
String msg = "Quarkus: CPU consumption is done with " + iterationsDone + " iterations in " + Duration.between(start, Instant.now()).getNano() + " nano-seconds.";
if (db) {
msg += " The result is persisted in the database.";
}
return msg;
}