Quatz job not getting triigered in spring with Quartz - java

below is my quatz integration with Spring but it is not working i.e. Job is not getting triggered . I can see quartz is checking MySQL database in few MS so that means connection with MYSQL is fine and also records are getting inserted in tables but Sysout mentioned in below class is not coming in console. please advice what could be root cause -
from Spring config XML
<bean id="myTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="5" />
<property name="maxPoolSize" value="50" />
<property name="WaitForTasksToCompleteOnShutdown" value="true" />
</bean>
<bean id="exampleBusinessObjectJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<bean name="exampleBusinessObjectJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="name" value="exampleBusinessObjectJob"/>
<property name="jobClass" value="com.aexp.mars.job.ExampleJob"/>
</bean>
</property>
<property name="cronExpression" value="0 */1 * * * ?"/>
</bean>
<bean id="exampleBusinessObjectJob" class="com.aexp.mars.job.ExampleJob">
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="applicationContextSchedulerContextKey" value="applicationContext"/>
<property name="autoStartup" value="true"/>
<property name="triggers">
<list>
<ref bean="exampleBusinessObjectJobTrigger" />
</list>
</property>
<property name="quartzProperties">
<props>
<prop key="org.quartz.scheduler.instanceName">MARS_SCHEDULER</prop>
<prop key="org.quartz.scheduler.instanceId">AUTO</prop>
<prop key="org.quartz.scheduler.instanceId">10000</prop>
<prop key="org.quartz.scheduler.instanceId">600000</prop>
<prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>
<prop key="org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread">true</prop>
<prop key="org.quartz.threadPool.threadCount">3</prop>
<prop key="org.quartz.threadPool.threadPriority">5</prop>
<prop key="org.quartz.jobStore.misfireThreshold">60000</prop>
<prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreTX</prop>
<prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.StdJDBCDelegate</prop>
<prop key="org.quartz.jobStore.useProperties">false</prop>
<prop key="org.quartz.jobStore.dataSource">marsDS</prop>
<prop key="org.quartz.jobStore.tablePrefix">QRTZ_</prop>
<prop key="org.quartz.jobStore.isClustered">true</prop>
<prop key="org.quartz.jobStore.clusterCheckinInterval">15000</prop>
<prop key="org.quartz.jobStore.maxMisfiresToHandleAtATime">20</prop>
<prop key="org.quartz.dataSource.marsDS.driver">com.mysql.jdbc.Driver</prop>
<prop key="org.quartz.dataSource.marsDS.URL">{server_url}</prop>
<prop key="org.quartz.dataSource.marsDS.user">{user_name}</prop>
<prop key="org.quartz.dataSource.marsDS.password">{password}</prop>
<prop key="org.quartz.dataSource.marsDS.maxConnections">10</prop>
<prop key="org.quartz.dataSource.marsDS.validationQuery">select 1</prop>
<prop key="org.quartz.plugin.shutdownHook.class">org.quartz.plugins.management.ShutdownHookPlugin</prop>
<prop key="org.quartz.plugin.shutdownHook.cleanShutdown">false</prop>
</props>
</property>
<property name="taskExecutor" ref="myTaskExecutor" />
<property name="jobFactory">
<bean class="com.aexp.mars.job.MarsSpringBeanJobFactory"/>
</property>
</bean>
**Java class - **
public class ExampleJob {
private static final Logger LOG = LoggerFactory.getLogger(ExampleJob.class);
protected void executeInternal(JobExecutionContext ctx) throws JobExecutionException {
System.out.println("Job is running");
LOG.info("Job ran");
}
public void execute(JobExecutionContext ctx) throws JobExecutionException {
System.out.println("Job#1 is running");
LOG.info("Job ran");
}
}

Got the scenario . I changed the value of cron expression to run it in every 1 minute but it was still set to my previous value (i.e. early morning 3 AM) . i added below property and then new cron expression startd working ..
<property name="overwriteExistingJobs" value="true"/>

Related

How to inject SchedulerFactoryBean after Spring 4.3.15 update

I am getting the following error after upgrading from Spring 4.3.2 to Spring 4.3.16:
org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'schedulerFactory': FactoryBean which is currently in creation returned null from getObject
I am injecting a Quartz Scheduler into one of my beans as follows:
// XML Config
<bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" autowire="byName">
<property name="jobFactory">
<bean class="org.springframework.scheduling.quartz.SpringBeanJobFactory"/>
</property>
<property name="applicationContextSchedulerContextKey" value="applicationContext"/>
<property name="dataSource" ref="myDS" />
<property name="triggers">
<list>
<ref bean="updateTrigger"/>
<ref bean="queueUpdateTrigger"/>
</list>
</property>
<property name="quartzProperties">
<props>
<prop key="org.quartz.scheduler.instanceName">MyQuartzScheduler</prop>
<prop key="org.quartz.scheduler.instanceId">AUTO</prop>
<prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreTX</prop>
<prop key="org.quartz.jobStore.isClustered">true</prop>
<prop key="org.quartz.jobStore.clusterCheckinInterval">60000</prop>
<prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.oracle.OracleDelegate</prop>
<prop key="org.quartz.jobStore.tablePrefix">QRTZ_</prop>
<prop key="org.quartz.threadPool.threadCount">2</prop>
<prop key="org.quartz.threadPool.threadPriority">5</prop>
<prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>
<prop key="org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread">true</prop>
</props>
</property>
</bean>
<bean name="UpdateJobUtils" class="app.job.UpdateJobUtils" autowire="byType">
<property name="schedulerFactory" ref="schedulerFactory" />
</bean>
//Bean
public class UpdateJobUtils {
private StdScheduler schedulerFactory;
public void setSchedulerFactory(StdScheduler schedulerFactory) {
this.schedulerFactory = schedulerFactory;
}
...
}
This worked in Spring 4.3.2 up until 4.3.14. I see https://jira.spring.io/browse/SPR-16439 was backported to 4.3.15 so I am wondering if it changes the way I am supposed to use this class?
schedulerFactory had autowire="byName" on its configuration.
I am not sure why that was on there, but removing it seems to have fixed the exception.

How to run multiple jobs in parallel using quartz simplethreadpool, Only one job runs and the other one fails

I have created two jobs, both will generate excel file.I need to generate multiple xlsx in parallel. But one job alone triggers at a time.
<bean id="breakFileXlsxTwo"
class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass"
value="com.citi.recon.quartz.BreakFileXlsxJobTwo" />
<property name="durability" value="true" />
</bean>
<bean id="breakFileXlsxTwoTrigger"
class="com.citi.recon.quartz.PersistableCronTriggerFactoryBean">
<property name="jobDetail" ref="breakFileXlsxTwo" />
<property name="cronExpression" value="0 0/10 * * * ?"/>
</bean>
<!-- cluster quartz, will only run in one server -->
<bean id="clusterquartzScheduler"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="applicationContextSchedulerContextKey" value="applicationContext" />
<property name="dataSource" ref="dataSource" />
<property name="transactionManager" ref="txManager" />
<property name="overwriteExistingJobs" value="true" />
<property name="autoStartup" value="true" />
<property name="quartzProperties">
<props>
<prop key="org.quartz.scheduler.instanceName">AMLReconQuartzScheduler</prop>
<prop key="org.quartz.scheduler.instanceId">AUTO</prop>
<prop key="org.quartz.jobStore.misfireThreshold">60000</prop>
<prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreTX</prop>
<prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.oracle.OracleDelegate
</prop>
<prop key="org.quartz.jobStore.tablePrefix">qrtz_</prop>
<prop key="org.quartz.jobStore.isClustered">true</prop>
<prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>
<prop key="org.quartz.threadPool.threadCount">30</prop>
<prop key="org.quartz.threadPool.threadPriority">5</prop>
<prop key="org.quartz.jobStore.useProperties">true</prop>
</props>
</property>
<property name="jobFactory">
<bean class="com.citi.recon.quartz.AutowiringSpringBeanJobFactory" />
</property>
<property name="jobDetails">
<list>
<ref bean="userSynchJob"/>
<ref bean="breakFileDownloadJob"/>
<ref bean="breakFileXlsxTwo"/>
</list>
</property>
<property name="triggers">
<list>
<ref bean="userSynchJobTrigger"/>
<ref bean="breakFileDownloadJobTrigger"/>
<ref bean="breakFileXlsxTwoTrigger"/>
</list>
</property>
</bean>
In both jobs, i have given same 10 mins time interval.
In my job class,i am extending QuartzJobBean like below:
public class BreakFileXlsxDownloadJob extends QuartzJobBean

Tomcat Data Source Losing Connection With DB

I need a solution about tomcat datasource configuration.
I have 2 nginx front of my tomcats.These are feeding my app, these are Webservice.
Tomcat machines and database are in different ip blog so its going firewall in each request.
When i started my tomcats everythigs well.But for example after 10 hour our after 20 hour later everythings going bad.That tomcats can not set connection.All service down.I share my datasource file and hope you find some solution or some other suggestions other than datasource file.
http://www.springframework.org/schema/beans ----
http://www.springframework.org/schema/context/spring-context.xsd">
<property name="connectionProperties">
<props merge="default">
<prop key="v$session.program">ws_${server}</prop>
</props>
</property>
<property name="connectionCacheProperties">
<props merge="default">
<prop key="MinLimit">1</prop>
<prop key="MaxLimit">120</prop>
<prop key="InitialLimit">5</prop>
<prop key="MaxStatementsLimit">50</prop>
<prop key="ConnectionWaitTimeout">30</prop>
<prop key="InactivityTimeout">600</prop>
<prop key="AbandonedConnectionTimeout">180</prop>
<prop key="PropertyCheckInterval">300</prop>
<prop key="ValidateConnection">true</prop>
<prop key="TimeToLiveTimeout">600</prop>
</props>
</property>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="nativeJdbcExtractor">
<bean class="org.springframework.jdbc.support.nativejdbc.SimpleNativeJdbcExtractor" />
</property>
<property name="dataSource" ref="dataSource" />
</bean>
<bean class="com.ws.oracle.pool.JndiExporter">
<property name="bean" ref="dataSource" />
<property name="jndiName" value="dsName" />
</bean>

Oracle Datasource invalid or stale object exception

I have a connection cache pool created and occasionally I get the Invalid stale connection object error. When I refresh the page and do the same operation it is working fine, means the exception is gone.
This is my config for the connection pool,
<bean id="myDataSource" class="oracle.jdbc.pool.OracleDataSource"
destroy-method="close">
<property name="connectionCachingEnabled" value="true" />
<property name="URL" value="${jdbcUrl-myapp}" />
<property name="user" value="${jdbcUsername-myapp}" />
<property name="password" value="${jdbcPassword-myapp}" />
<property name="connectionProperties">
<value>
oracle.jdbc.timezoneAsRegion=false
</value>
</property>
<property name="connectionCacheProperties">
<props merge="default">
<prop key="MinLimit">0</prop>
<prop key="MaxLimit">100</prop>
<prop key="InitialLimit">1</prop>
<prop key="ConnectionWaitTimeout">600</prop>
<prop key="InactivityTimeout">300</prop>
<prop key="ValidateConnection">true</prop>
</props>
</property>
</bean>
Basically you need to get ride of invalid/stale connection.
Try following set of properties:
<bean id="myDataSource" class="oracle.jdbc.pool.OracleDataSource"
destroy-method="close">
<property name="connectionCachingEnabled" value="true" />
<property name="URL" value="${jdbcUrl-myapp}" />
<property name="user" value="${jdbcUsername-myapp}" />
<property name="password" value="${jdbcPassword-myapp}" />
<property name="connectionProperties">
<value>
oracle.jdbc.timezoneAsRegion=false
</value>
</property>
<property name="connectionCacheProperties">
<props merge="default">
<prop key="MinLimit">0</prop>
<prop key="MaxLimit">100</prop>
<prop key="InitialLimit">1</prop>
<prop key="ConnectionWaitTimeout">600</prop>
<prop key="InactivityTimeout">300</prop>
<prop key="ValidateConnection">true</prop>
<prop key="testOnBorrow">true</prop>
<prop key="testOnReturn">true</prop>
<prop key="testWhileIdle">true</prop>
<prop key="validationQuery">select 1 from dual</prop>
<prop key="removeAbandoned">true</prop>
</props>
</property>
</bean>

spring hibernate configuration using resource_local or jta by default?

may i know as my configuration is done directly on applicationContext.xml, i do not have persistence.xml . by default this is resource_loca or jta? do i need to add extra parameter if i want to use jta?
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>oracle.jdbc.driver.OracleDriver</value>
</property>
<!-- xdb is defined by running the hsqldb as xdb (see above) -->
<property name="url">
<value>jdbc:oracle:thin:#theserver:1521:appsdb</value>
</property>
<property name="username">
<value>test</value>
</property>
<property name="password">
<value>test</value>
</property>
</bean>
<bean id="annotatedsessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="packagesToScan" value="com.company.x.model" >
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.use_sql_comments">true</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.c3p0.min_size">5</prop>
<prop key="hibernate.c3p0.max_size">20</prop>
<prop key="hibernate.c3p0.timeout">1800</prop>
<prop key="hibernate.c3p0.max_statements">50</prop>
<prop key="hibernate.cache.provider_class">
com.company.x.services.ExternalEhCacheProvider
</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
</props>
</property>
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>
RESOURCE_LOCAL only applies to JPA EntityManager, not to a Hibernate SessionFactory. Hibernate's Spring integration is rather smoother than it is with JPA, and so the only thing that determines the transactional behaviour is which transaction manager you use with it (either HibernateTransactionManager or JtaTransactionManager). It'll work with either one without you having to explicitly configure the SessionFactory.

Categories

Resources