Skip to content

Commit

Permalink
Scheduler: add custom thread factory to use a specific thread name
Browse files Browse the repository at this point in the history
- also fix the CronTrigger "fired" log TRACE message
  • Loading branch information
mkouba committed Jun 17, 2024
1 parent 68b4cae commit e3fa7f1
Showing 1 changed file with 22 additions and 2 deletions.
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

0 comments on commit e3fa7f1

Please sign in to comment.