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

Scheduler: add custom thread factory to use a specific thread name #41242

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

import jakarta.annotation.PreDestroy;
Expand Down Expand Up @@ -135,8 +137,26 @@ public SimpleScheduler(SchedulerContext context, SchedulerRuntimeConfig schedule
return;
}

ThreadFactory tf = new ThreadFactory() {

private final AtomicInteger threadNumber = new AtomicInteger(1);

@Override
public Thread newThread(Runnable runnable) {
Thread t = new Thread(Thread.currentThread().getThreadGroup(), runnable,
"quarkus-scheduler-trigger-check-" + threadNumber.getAndIncrement(),
0);
if (t.isDaemon()) {
t.setDaemon(false);
}
if (t.getPriority() != Thread.NORM_PRIORITY) {
t.setPriority(Thread.NORM_PRIORITY);
}
return t;
}
};
// This executor is used to check all registered triggers every second
this.scheduledExecutor = new JBossScheduledThreadPoolExecutor(1, new Runnable() {
this.scheduledExecutor = new JBossScheduledThreadPoolExecutor(1, tf, new Runnable() {
@Override
public void run() {
// noop
Expand Down Expand Up @@ -589,7 +609,7 @@ ZonedDateTime evaluate(ZonedDateTime now) {
if (lastExecution.isPresent()) {
ZonedDateTime lastTruncated = lastExecution.get().truncatedTo(ChronoUnit.SECONDS);
if (zonedNow.isAfter(lastTruncated) && lastFireTime.isBefore(lastTruncated)) {
LOG.tracef("%s fired, last=", this, lastTruncated);
LOG.tracef("%s fired, last=%s", this, lastTruncated);
lastFireTime = zonedNow;
return lastTruncated;
}
Expand Down