diff --git a/extensions/quartz/deployment/src/test/java/io/quarkus/quartz/test/DependentBeanJobTest.java b/extensions/quartz/deployment/src/test/java/io/quarkus/quartz/test/DependentBeanJobTest.java index 9a2943c1ab78a..410018b410a2b 100644 --- a/extensions/quartz/deployment/src/test/java/io/quarkus/quartz/test/DependentBeanJobTest.java +++ b/extensions/quartz/deployment/src/test/java/io/quarkus/quartz/test/DependentBeanJobTest.java @@ -86,10 +86,10 @@ public void testDependentBeanJobDestroyed() throws SchedulerException, Interrupt @Test public void testDependentBeanJobWithRefire() throws SchedulerException, InterruptedException { - // 5 one-off jobs should trigger construction/execution/destruction 10 times in total - CountDownLatch execLatch = service.initExecuteLatch(10); - CountDownLatch constructLatch = service.initConstructLatch(10); - CountDownLatch destroyedLatch = service.initDestroyedLatch(10); + // 5 one-off jobs should trigger construction/execution/destruction 5 times in total + CountDownLatch execLatch = service.initExecuteLatch(5); + CountDownLatch constructLatch = service.initConstructLatch(5); + CountDownLatch destroyedLatch = service.initDestroyedLatch(5); for (int i = 0; i < 5; i++) { Trigger trigger = TriggerBuilder.newTrigger() .withIdentity("myTrigger" + i, "myRefiringGroup") @@ -104,10 +104,10 @@ public void testDependentBeanJobWithRefire() throws SchedulerException, Interrup assertTrue(constructLatch.await(2, TimeUnit.SECONDS), "Latch count: " + constructLatch.getCount()); assertTrue(destroyedLatch.await(2, TimeUnit.SECONDS), "Latch count: " + destroyedLatch.getCount()); - // repeating job triggering three times; we expect six beans to exist for that due to refires - execLatch = service.initExecuteLatch(6); - constructLatch = service.initConstructLatch(6); - destroyedLatch = service.initDestroyedLatch(6); + // repeating job triggering three times; re-fires should NOT recreate the bean instance + execLatch = service.initExecuteLatch(3); + constructLatch = service.initConstructLatch(3); + destroyedLatch = service.initDestroyedLatch(3); JobDetail job = JobBuilder.newJob(RefiringJob.class) .withIdentity("myRepeatingJob", "myRefiringGroup") .build(); diff --git a/extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/CdiAwareJob.java b/extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/CdiAwareJob.java index 4e02136078ef9..fde25d16681d7 100644 --- a/extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/CdiAwareJob.java +++ b/extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/CdiAwareJob.java @@ -28,10 +28,14 @@ public CdiAwareJob(Instance jobInstance) { @Override public void execute(JobExecutionContext context) throws JobExecutionException { Instance.Handle handle = jobInstance.getHandle(); + boolean refire = false; try { handle.get().execute(context); + } catch (JobExecutionException e) { + refire = e.refireImmediately(); + throw e; } finally { - if (handle.getBean().getScope().equals(Dependent.class)) { + if (refire != true && handle.getBean().getScope().equals(Dependent.class)) { handle.destroy(); } }