diff --git a/etc/scripts/updateparent.awk b/etc/scripts/updateparent.awk index 49316a038..a21043949 100644 --- a/etc/scripts/updateparent.awk +++ b/etc/scripts/updateparent.awk @@ -1,6 +1,6 @@ #!awk -f # -# Copyright (c) 2023 Oracle and/or its affiliates. +# Copyright (c) 2023, 2024 Oracle and/or its affiliates. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/webserver/threads/src/main/java/io/helidon/examples/webserver/threads/Main.java b/examples/webserver/threads/src/main/java/io/helidon/examples/webserver/threads/Main.java index 41e008633..6ac6d6ed9 100644 --- a/examples/webserver/threads/src/main/java/io/helidon/examples/webserver/threads/Main.java +++ b/examples/webserver/threads/src/main/java/io/helidon/examples/webserver/threads/Main.java @@ -16,8 +16,8 @@ package io.helidon.examples.webserver.threads; -import io.helidon.logging.common.LogConfig; import io.helidon.config.Config; +import io.helidon.logging.common.LogConfig; import io.helidon.webclient.api.WebClient; import io.helidon.webserver.WebServer; import io.helidon.webserver.http.HttpRouting; @@ -27,7 +27,7 @@ */ public class Main { - static WebClient webclient; + private static WebClient webclient; /** * Cannot be instantiated. @@ -40,7 +40,7 @@ private Main() { * @param args command line arguments. */ public static void main(String[] args) { - + // load logging configuration LogConfig.configureRuntime(); @@ -70,4 +70,8 @@ static void routing(HttpRouting.Builder routing) { routing .register("/thread", new ThreadService()); } -} \ No newline at end of file + + static WebClient webClient() { + return webclient; + } +} diff --git a/examples/webserver/threads/src/main/java/io/helidon/examples/webserver/threads/ThreadService.java b/examples/webserver/threads/src/main/java/io/helidon/examples/webserver/threads/ThreadService.java index 60ece4b13..65750d13f 100644 --- a/examples/webserver/threads/src/main/java/io/helidon/examples/webserver/threads/ThreadService.java +++ b/examples/webserver/threads/src/main/java/io/helidon/examples/webserver/threads/ThreadService.java @@ -37,7 +37,7 @@ class ThreadService implements HttpService { private static final System.Logger LOGGER = System.getLogger(ThreadService.class.getName()); - private static final Random rand = new Random(System.currentTimeMillis()); + private static final Random RANDOM = new Random(System.currentTimeMillis()); // ThreadPool of platform threads. private static ExecutorService platformExecutorService; @@ -133,7 +133,7 @@ private void fanOutHandler(ServerRequest request, ServerResponse response) { // For this we use our virtual thread based executor. We submit the work and save the Futures var futures = new ArrayList>(); for (int i = 0; i < count; i++) { - futures.add(virtualExecutorService.submit(() -> callRemote(rand.nextInt(5)))); + futures.add(virtualExecutorService.submit(() -> callRemote(RANDOM.nextInt(5)))); } // After work has been submitted we loop through the future and block getting the results. @@ -156,14 +156,14 @@ private void fanOutHandler(ServerRequest request, ServerResponse response) { } /** - * Simulate a remote client call by calling this server's sleep endpoint + * Simulate a remote client call by calling this server's sleep endpoint. * - * @param seconds number of seconds the endpoint should sleep. + * @param seconds number of seconds the endpoint should sleep * @return string response from client */ private String callRemote(int seconds) { LOGGER.log(Level.INFO, Thread.currentThread() + ": Calling remote sleep for " + seconds + "s"); - WebClient client = Main.webclient; + WebClient client = Main.webClient(); ClientResponseTyped response = client.get("/sleep/" + seconds).request(String.class); if (response.status().equals(Status.OK_200)) { return response.entity(); @@ -172,7 +172,7 @@ private String callRemote(int seconds) { } /** - * Sleep current thread + * Sleep current thread. * * @param seconds number of seconds to sleep * @return number of seconds requested to sleep @@ -187,14 +187,14 @@ private int sleep(int seconds) { } /** - * Perform a CPU intensive computation + * Perform a CPU intensive computation. * * @param iterations: number of times to perform computation * @return result of computation */ private double compute(int iterations) { LOGGER.log(Level.INFO, Thread.currentThread() + ": Computing with " + iterations + " iterations"); - double d = 123456789.123456789 * rand.nextInt(100); + double d = 123456789.123456789 * RANDOM.nextInt(100); for (int i = 0; i < iterations; i++) { for (int n = 0; n < 1_000_000; n++) { for (int j = 0; j < 5; j++) {