Skip to content
Merged
Show file tree
Hide file tree
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 @@ -15,6 +15,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -176,6 +177,7 @@ void collectScheduledMethods(BeanArchiveIndexBuildItem beanArchives, BeanDiscove
BuildProducer<ScheduledBusinessMethodItem> scheduledBusinessMethods) {

// First collect static scheduled methods
Map<MethodInfo, List<AnnotationInstance>> staticScheduledMethods = new HashMap<>();
List<AnnotationInstance> schedules = new ArrayList<>(
beanArchives.getIndex().getAnnotations(SchedulerDotNames.SCHEDULED_NAME));
for (AnnotationInstance annotationInstance : beanArchives.getIndex().getAnnotations(SchedulerDotNames.SCHEDULES_NAME)) {
Expand All @@ -198,13 +200,23 @@ void collectScheduledMethods(BeanArchiveIndexBuildItem beanArchives, BeanDiscove
method.name(), declaringClass.name()));
}
if (Modifier.isStatic(method.flags()) && !KotlinUtil.isSuspendMethod(method)) {
scheduledBusinessMethods.produce(new ScheduledBusinessMethodItem(null, method, schedules,
transformedAnnotations.hasAnnotation(method, SchedulerDotNames.NON_BLOCKING),
transformedAnnotations.hasAnnotation(method, SchedulerDotNames.RUN_ON_VIRTUAL_THREAD)));
LOGGER.debugf("Found scheduled static method %s declared on %s", method, declaringClass.name());
List<AnnotationInstance> methodSchedules = staticScheduledMethods.get(method);
if (methodSchedules == null) {
methodSchedules = new ArrayList<>();
staticScheduledMethods.put(method, methodSchedules);
}
methodSchedules.add(annotationInstance);
}
}

for (Entry<MethodInfo, List<AnnotationInstance>> e : staticScheduledMethods.entrySet()) {
MethodInfo method = e.getKey();
scheduledBusinessMethods.produce(new ScheduledBusinessMethodItem(null, method, e.getValue(),
transformedAnnotations.hasAnnotation(method, SchedulerDotNames.NON_BLOCKING),
transformedAnnotations.hasAnnotation(method, SchedulerDotNames.RUN_ON_VIRTUAL_THREAD)));
LOGGER.debugf("Found scheduled static method %s declared on %s", method, method.declaringClass().name());
}

// Then collect all business methods annotated with @Scheduled
for (BeanInfo bean : beanDiscovery.beanStream().classBeans()) {
collectScheduledMethods(beanArchives.getIndex(), transformedAnnotations, bean,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package io.quarkus.scheduler.test.staticmethod;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import jakarta.inject.Inject;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.scheduler.Scheduled;
import io.quarkus.scheduler.Scheduler;
import io.quarkus.test.QuarkusUnitTest;

public class ScheduledStaticMethodTest {
Expand All @@ -18,8 +22,12 @@ public class ScheduledStaticMethodTest {
.withApplicationRoot((jar) -> jar
.addClasses(Jobs.class, AbstractJobs.class, InterfaceJobs.class));

@Inject
Scheduler scheduler;

@Test
public void testSimpleScheduledJobs() throws InterruptedException {
assertEquals(3, scheduler.getScheduledJobs().size());
assertTrue(Jobs.LATCH.await(5, TimeUnit.SECONDS));
assertTrue(AbstractJobs.LATCH.await(5, TimeUnit.SECONDS));
assertTrue(InterfaceJobs.LATCH.await(5, TimeUnit.SECONDS));
Expand Down
Loading