Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
3 tasks done
Hans-Wu-cn opened this issue Feb 22, 2024 · 3 comments
Open
3 tasks done

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

Hans-Wu-cn opened this issue Feb 22, 2024 · 3 comments

Comments

@Hans-Wu-cn
Copy link

Hans-Wu-cn commented Feb 22, 2024

Prerequisites

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

  • I am running the latest version
  • I checked the documentation and found no answer
  • I checked to make sure that this issue has not already been filed

Expected Behavior

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

@kagkarlsson
Copy link
Owner

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
Copy link
Author

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
Copy link
Contributor

NicklasWallgren commented May 16, 2024

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));
    }

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants