kagkarlsson / db-scheduler

Persistent cluster-friendly scheduler for Java
Apache License 2.0
1.19k stars 183 forks source link

Do you consider supporting Solon, Java21, and virtual threads #470

Open Hans-Wu-cn opened 5 months ago

Hans-Wu-cn commented 5 months ago

Prerequisites

Please answer the following questions for yourself before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.

Expected Behavior

Hello @kagkarlsson , may I ask if it supports solon and Java21 and virtual threads? This is very important

kagkarlsson commented 5 months ago

Hi! I am not familiar with Solon, though db-scheduler should be easy to setup in any framework. I have not tried it with virtual threads, but I believe it should work if you send in an ExecutorService based on virtual threads

Hans-Wu-cn commented 5 months ago

Hi! I am not familiar with Solon, though db-scheduler should be easy to setup in any framework. I have not tried it with virtual threads, but I believe it should work if you send in an based on virtual threadsExecutorService

Before this, I had tried to adapt to console+db scheduler, but I am very unfamiliar with db scheduler and cannot adapt. I have already implemented a custom thread pool for virtual threads in quatrz. which is very simple because many platform threads need to do operations, and virtual threads do not need to do them. They will automatically recycle them

NicklasWallgren commented 2 months ago

You can create custom executor services with help of the DbSchedulerCustomizer, see the example below.

@Component
@RequiredArgsConstructor
public class DbSchedulerCustomizer implements com.github.kagkarlsson.scheduler.boot.config.DbSchedulerCustomizer {

    private final DbSchedulerProperties dbSchedulerProperties;

    @Override
    public Optional<ExecutorService> executorService() {
        final ThreadFactory threadFactory = Thread.ofVirtual()
            .name(Scheduler.THREAD_PREFIX + "-execute-task-", 1)
            .factory();

        return Optional.of(Executors.newScheduledThreadPool(dbSchedulerProperties.getThreads(), threadFactory));
    }

    @Override
    public Optional<ExecutorService> dueExecutor() {
        final ThreadFactory threadFactory = Thread.ofVirtual()
            .name(Scheduler.THREAD_PREFIX + "-execute-due-", 1)
            .factory();

        return Optional.of(Executors.newSingleThreadExecutor(threadFactory));
    }

    @Override
    public Optional<ScheduledExecutorService> housekeeperExecutor() {
        final ThreadFactory threadFactory = Thread.ofVirtual()
            .name(Scheduler.THREAD_PREFIX + "-housekeeper-", 1)
            .factory();

        return Optional.of(Executors.newScheduledThreadPool(3, threadFactory));
    }

}