RFR: CODETOOLS-7903464: add VirtualThreadExecutor to the list of predefined worker threads executors

Aleksey Shipilev shade at openjdk.org
Tue May 2 07:22:43 UTC 2023


On Tue, 2 May 2023 07:01:49 GMT, Sergey Kuksenko <skuksenko at openjdk.org> wrote:

> The list of working threads executors should be expanded with virtual threads executor.
> Added VIRTUAL_TPE which is  "Executors.newFixedThreadPool(maxThreads, virtualThreadFactory)).

Looks okay, some comments:

jmh-core/src/main/java/org/openjdk/jmh/runner/WorkerThreadFactories.java line 2:

> 1: /*
> 2:  * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.

Copyright years need to be updated.

jmh-core/src/main/java/org/openjdk/jmh/runner/WorkerThreadFactories.java line 36:

> 34: class WorkerThreadFactories {
> 35: 
> 36:     static class WorkerThreadFactory implements ThreadFactory {

This is `PlatformThreadFactory` now?

jmh-core/src/main/java/org/openjdk/jmh/runner/WorkerThreadFactories.java line 57:

> 55:     }
> 56: 
> 57:     static ThreadFactory getPlatformWorkerFactory(String prefix) {

`Workers.platformWorkerFactory` and `Workers.virtualWorkerFactory` might be better namess.

jmh-core/src/main/java/org/openjdk/jmh/runner/WorkerThreadFactories.java line 62:

> 60: 
> 61:     static ThreadFactory getVirtualWorkerFactory(String prefix) {
> 62:         // requires reflection to be compilable in pre JDK 21

Suggestion:

        // This API is only available in JDK 21+. Use reflection to make the code compilable with lower JDKs.

jmh-core/src/main/java/org/openjdk/jmh/runner/WorkerThreadFactories.java line 72:

> 70:             return (ThreadFactory) m.invoke(threadBuilder);
> 71:         } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException |
> 72:                  ClassNotFoundException  | NullPointerException e) {

Suggestion:

                 ClassNotFoundException | NullPointerException e) {

jmh-core/src/main/java/org/openjdk/jmh/runner/WorkerThreadFactories.java line 73:

> 71:         } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException |
> 72:                  ClassNotFoundException  | NullPointerException e) {
> 73:             throw new RuntimeException("Can't instantiate VirtualThreadFactory", e);

Suggestion:

            throw new RuntimeException("Cannot instantiate VirtualThreadFactory", e);

-------------

PR Review: https://git.openjdk.org/jmh/pull/102#pullrequestreview-1408520724
PR Review Comment: https://git.openjdk.org/jmh/pull/102#discussion_r1182169894
PR Review Comment: https://git.openjdk.org/jmh/pull/102#discussion_r1182174262
PR Review Comment: https://git.openjdk.org/jmh/pull/102#discussion_r1182177201
PR Review Comment: https://git.openjdk.org/jmh/pull/102#discussion_r1182172967
PR Review Comment: https://git.openjdk.org/jmh/pull/102#discussion_r1182172217
PR Review Comment: https://git.openjdk.org/jmh/pull/102#discussion_r1182175525


More information about the jmh-dev mailing list