Skip to content

Ease the creation of multiple task executor and task scheduled builders #39928

Open
@frosiere

Description

@frosiere

Through an auto-configuration, Spring Boot makes it easy to create a task executor builder and a task scheduled builders with their respective sets of properties.

In most cases, this is sufficient, but in some specific cases, it may be necessary to create multiple builders with multiple sets of properties. In this case, the configuration has to be defined manually, resulting in some duplication of Spring Boot code.

It would be great if Spring Boot could provide an easy way to create these builders from a given property class.

Let's take a concrete example. Suppose an application needs to create 2 ThreadPoolTaskSchedulerBuilder with 2 sets of properties.
The support could be given as follows

TaskSchedulingProperties taskSchedulingProperties1 = new TaskSchedulingProperties();
ThreadPoolTaskSchedulerBuilder taskSchedulerBuilder1 = xxx.create(taskSchedulingProperties);

TaskSchedulingProperties taskSchedulingProperties2 = new TaskSchedulingProperties();
ThreadPoolTaskSchedulerBuilder taskSchedulerBuilder2 = xxx.create(taskSchedulingProperties);

xxx could either be a factory, a utility class or a static method on the property class itself.

Our use case is to create several builders in different contexts such as grpc, kafka, etc.

In previous versions of Spring boot, it was possible to abuse the use of auto-configurations as follows

    TaskExecutorBuilder createTaskExecutorBuilder(TaskExecutionProperties properties) {
        return new TaskExecutionAutoConfiguration().taskExecutorBuilder(
                properties, 
                new EmptyObjectProvider<>(), 
                new EmptyObjectProvider<>()
        );
    }
    TaskSchedulerBuilder createTaskSchedulerBuilder(TaskSchedulingProperties properties) {
        return new TaskSchedulingAutoConfiguration().taskSchedulerBuilder(
                properties, 
                new EmptyObjectProvider<>()
        );
    }

Any feedback or comments are more than welcome.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions