Hello,
I have observed a memory leak for Quartz worker thread in case an exception is thrown during the scheduling phase when schedule is set to past time. I have observed this issue with camel-quart 2.10.4, 2.11.0, 2.11.2 versions. For ex, assuming today is 4-Oct; If a schedule is provided for yesterday (i.e 3-Oct) then below sequence happen: 1. Quartz create worker thread for new schedule [generally TEN Threads with name 'DefaultQuartzScheduler'] 2. Camel-quartz increment jobCounter for scheduler context [using QuartzComponent.incrementJobCounter()] 3. Camel-quartz tries to create new schedule [using Scheduler.scheduleJob()] 4. scheduleJob() throws SchedulerException with the message - 'Based on configured schedule, the given trigger will never fire' 5. Camel-quartz does NOT decrement the job counter and jobCounter value remains '1' 6. Later Camel-Quartz stops the route and call QuartzComponent.doStop() 7. In doStop(), Scheduler.shutdown() supposed to be called so that those TEN threads are removed but to call shutdown() the pre-condition is that the jobCounter should be '0'. In this case jobCounter is '1' and Scheduler.shutdown() will NOT be called and those TEN threads are NOT removed. This is memory leak. Please find the stack trace [with Camel-Quartz 2.11.2 and org.apache.servicemix.bundles.quartz-1.8.6_1 which wrapped Quartz Scheduler as OSGi bundle] when SchedulerException is thrown at step 4 in above sequence. Let me know if you want me to create JIRA issue. Thanks, Nurali ** Stack Trace: 15:55:22.432 ERROR [Blueprint Extender: 1] o.a.c.b.BlueprintCamelContext [BlueprintCamelContext.java:139] - Error occurred during starting Camel: CamelContext(sfsftest35) due Based on configured schedule, the given trigger will never fire. org.quartz.SchedulerException: Based on configured schedule, the given trigger will never fire. at org.quartz.core.QuartzScheduler.scheduleJob(QuartzScheduler.java:793) ~[na:na] at org.quartz.impl.StdScheduler.scheduleJob(StdScheduler.java:243) ~[na:na] at org.apache.camel.component.quartz.QuartzComponent.doAddJob(QuartzComponent.java:232) ~[na:na] at org.apache.camel.component.quartz.QuartzComponent.addJob(QuartzComponent.java:222) ~[na:na] at org.apache.camel.component.quartz.QuartzEndpoint.addTrigger(QuartzEndpoint.java:81) ~[na:na] at org.apache.camel.component.quartz.QuartzEndpoint.consumerStarted(QuartzEndpoint.java:213) ~[na:na] at org.apache.camel.component.quartz.QuartzConsumer.doStart(QuartzConsumer.java:39) ~[na:na] at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61) ~[na:na] at org.apache.camel.impl.DefaultCamelContext.startService(DefaultCamelContext.java:1819) ~[na:na] at org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRouteConsumers(DefaultCamelContext.java:2113) ~[na:na] at org.apache.camel.impl.DefaultCamelContext.doStartRouteConsumers(DefaultCamelContext.java:2049) ~[na:na] at org.apache.camel.impl.DefaultCamelContext.safelyStartRouteServices(DefaultCamelContext.java:1979) ~[na:na] at org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRoutes(DefaultCamelContext.java:1758) ~[na:na] at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1633) ~[na:na] at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1500) ~[na:na] at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61) ~[na:na] at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1468) ~[na:na] at org.apache.camel.blueprint.BlueprintCamelContext.start(BlueprintCamelContext.java:167) [bundlefile:2.11.2] at org.apache.camel.blueprint.BlueprintCamelContext.maybeStart(BlueprintCamelContext.java:199) [bundlefile:2.11.2] at org.apache.camel.blueprint.BlueprintCamelContext.serviceChanged(BlueprintCamelContext.java:137) [bundlefile:2.11.2] at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:107) [org.eclipse.org.eclipse.osgi-3.8.0.v20120529-1548.jar:na] at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:861) [org.eclipse.org.eclipse.osgi-3.8.0.v20120529-1548.jar:na] at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230) [org.eclipse.org.eclipse.osgi-3.8.0.v20120529-1548.jar:na] at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148) [org.eclipse.org.eclipse.osgi-3.8.0.v20120529-1548.jar:na] at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:819) [org.eclipse.org.eclipse.osgi-3.8.0.v20120529-1548.jar:na] at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:771) [org.eclipse.org.eclipse.osgi-3.8.0.v20120529-1548.jar:na] at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:130) [org.eclipse.org.eclipse.osgi-3.8.0.v20120529-1548.jar:na] at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:214) [org.eclipse.org.eclipse.osgi-3.8.0.v20120529-1548.jar:na] at org.eclipse.osgi.framework.internal.core.BundleContextImpl.registerService(BundleContextImpl.java:433) [org.eclipse.org.eclipse.osgi-3.8.0.v20120529-1548.jar:na] at org.eclipse.osgi.framework.internal.core.BundleContextImpl.registerService(BundleContextImpl.java:451) [org.eclipse.org.eclipse.osgi-3.8.0.v20120529-1548.jar:na] at org.eclipse.osgi.framework.internal.core.BundleContextImpl.registerService(BundleContextImpl.java:950) [org.eclipse.org.eclipse.osgi-3.8.0.v20120529-1548.jar:na] at org.apache.camel.blueprint.BlueprintCamelContext.init(BlueprintCamelContext.java:96) [bundlefile:2.11.2] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_40] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_40] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_40] at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.7.0_40] at org.apache.aries.blueprint.utils.ReflectionUtils.invoke(ReflectionUtils.java:297) [bundlefile:1.1.0-sap-01] at org.apache.aries.blueprint.container.BeanRecipe.invoke(BeanRecipe.java:958) [bundlefile:1.1.0-sap-01] at org.apache.aries.blueprint.container.BeanRecipe.runBeanProcInit(BeanRecipe.java:712) [bundlefile:1.1.0-sap-01] at org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:824) [bundlefile:1.1.0-sap-01] at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:787) [bundlefile:1.1.0-sap-01] at org.apache.aries.blueprint.di.AbstractRecipe$1.call(AbstractRecipe.java:79) [bundlefile:1.1.0-sap-01] at java.util.concurrent.FutureTask.run(Unknown Source) [na:1.7.0_40] at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:88) [bundlefile:1.1.0-sap-01] at org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:245) [bundlefile:1.1.0-sap-01] at org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:183) [bundlefile:1.1.0-sap-01] at org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:668) [bundlefile:1.1.0-sap-01] at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:370) [bundlefile:1.1.0-sap-01] at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:261) [bundlefile:1.1.0-sap-01] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [na:1.7.0_40] at java.util.concurrent.FutureTask.run(Unknown Source) [na:1.7.0_40] at org.apache.aries.blueprint.container.ExecutorServiceWrapper.run(ExecutorServiceWrapper.java:106) [bundlefile:1.1.0-sap-01] at org.apache.aries.blueprint.utils.threading.impl.DiscardableRunnable.run(DiscardableRunnable.java:48) [bundlefile:1.1.0-sap-01] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [na:1.7.0_40] at java.util.concurrent.FutureTask.run(Unknown Source) [na:1.7.0_40] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown Source) [na:1.7.0_40] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) [na:1.7.0_40] at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.7.0_40] at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.7.0_40] at java.lang.Thread.run(Unknown Source) [na:1.7.0_40]