quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.82k stars 2.69k forks source link

ThreadFactory injection in user's application #13874

Open r00ta opened 3 years ago

r00ta commented 3 years ago

Description In some use cases, the application might need a ThreadFactory and afaik at the moment it's not possible to get it out of Quarkus. By consequence, the developer has to create and manage another thread pool which might not be an optimal implementation.

For example, in Springboot it's possible to inject this https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutor.html and this https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/scheduling/concurrent/ThreadPoolExecutorFactoryBean.html

It might be nice to have something similar also in Quarkus.

Implementation ideas (If you have any implementation ideas, they can go here, however please note that all design change proposals should be posted to the Quarkus developer mailing list (or the corresponding Google Group; see the decisions process document for more information).

ghost commented 3 years ago

/cc @manovotn, @mkouba

manovotn commented 3 years ago

Hi @r00ta,

you could leverage MP Context Propagation in Quarkus. That way, you can inject ManagedExecutor, which is under Quarkus management, and you use that freely. You also get to specify if you want some context propagation as well as max async and queue sizes if you use the builder pattern to create your own. I think that is something you are looking for, right?

The dependency for this extension looks like this:

    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-smallrye-context-propagation</artifactId>
    </dependency>
r00ta commented 3 years ago

Hi @r00ta,

you could leverage MP Context Propagation in Quarkus. That way, you can inject ManagedExecutor, which is under Quarkus management, and you use that freely. You also get to specify if you want some context propagation as well as max async and queue sizes if you use the builder pattern to create your own. I think that is something you are looking for, right?

The dependency for this extension looks like this:

    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-smallrye-context-propagation</artifactId>
    </dependency>

Hi @manovotn , thanks for the reply! My main concern is that ManagedExecutor only provides an executor (and I see that the user's code should leverage on that), but some libraries require a ThreadFactory and not only an executor: this is something not under control of the user.

Just an example: micrometer (https://github.com/micrometer-metrics/micrometer/blob/37360582d35947fbc4c7479886ce6ebbe6a8086a/micrometer-core/src/main/java/io/micrometer/core/instrument/push/PushMeterRegistry.java#L66). I know Quarkus already provides support for micrometer, but this is not really the point.