Skip to content

Commit

Permalink
Fix copyright and checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
romain-grecourt committed Aug 6, 2024
1 parent 283e94f commit fafef95
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion etc/scripts/updateparent.awk
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,7 +27,7 @@
*/
public class Main {

static WebClient webclient;
private static WebClient webclient;

/**
* Cannot be instantiated.
Expand All @@ -40,7 +40,7 @@ private Main() {
* @param args command line arguments.
*/
public static void main(String[] args) {

// load logging configuration
LogConfig.configureRuntime();

Expand Down Expand Up @@ -70,4 +70,8 @@ static void routing(HttpRouting.Builder routing) {
routing
.register("/thread", new ThreadService());
}
}

static WebClient webClient() {
return webclient;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Future<String>>();
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.
Expand All @@ -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<String> response = client.get("/sleep/" + seconds).request(String.class);
if (response.status().equals(Status.OK_200)) {
return response.entity();
Expand All @@ -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
Expand All @@ -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++) {
Expand Down

0 comments on commit fafef95

Please sign in to comment.