Skip to content

Implement an ExecutorServiceFactory that creates ExecutorServices that supports virtual Threads #3600

@nordicthings

Description

@nordicthings

Enhancement Description

The ThreadPoolExecutor-implementations we currently use do not support virtual threads. Theoretically, we could use a ThreadPoolExecutor which creates virtual threads instead of platform threads, like this:

ExecutorService executor = new ThreadPoolExecutor(
    1,                                    // corePoolSize (irrelevant for virtual threads)
    1,                                    // maximumPoolSize
    0L, TimeUnit.SECONDS,                 // keepAliveTime (irrelevant)
    new PriorityBlockingQueue<>(1000)(),  // workQueue
    Thread.ofVirtual().factory()          // Virtual Thread Factory
);

However, this is probably not ideal because we no longer need a classic pool for virtual threads: for each new task, a virtual thread is simply created and released again once the task is complete.
Furthermore, we still need to support priorities in task processing.
We should build an implementation for the ExecutorServiceFactory that builds an ExecutorService that supports virtual threads and uses a PriorityBlockingQueue for priority-based task processing.

Current Behaviour

The ExecutorServiceFactory creates classic ThreadPoolExecutors that uses platform-threads.

Wanted Behaviour

The ExecutorServiceFactory creates a custom ExecutorService-implementation that uses virtual threads and supports priority-based task processing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority 3: CouldLow priority. Issues that are nice to have but have a straightforward workaround.Type: EnhancementUse to signal an issue enhances an already existing feature of the project.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions