Quartz integration with spring
About the basic knowledge of quartz, here is no longer said, you can refer to the quartz example.
The main thing to say here is that the individual has problems and personal understanding in the process of quartz and spring integration.
First of all, personal understanding:
1, the operation principle of quartz
An important part of quartz is the thread pool and the trigger. And these resources are managed by a class called Standscheduler.
So, every time the Quartz program starts, it needs to create a scheduler object that manages quartz resources. When it starts, it starts the quartz dispatch thread first, and then initializes the thread in the thread pool.
Whenever a trigger is in effect, a thread is fetched from the thread pool, and the Execute method of the corresponding job is invoked to begin execution.
2.Quartz Job How to cancel
First your job is to inherit from Interruptablejob, but when the job's interrupt method is called, you can set a flag to indicate that it has been cancel, and the Execute method constantly detects this flag and discovers Cacel, then interrupts the current job.
3.Quartz how to embed in spring
The first thing to understand is how quartz starts spring. And look at the configuration of the following pring:
<bean id= "Schedulerfactory" class= "Org.springframework.scheduling.quartz.SchedulerFactoryBean" >
<property name= "configlocation" value= "/web-inf/classes/quartz.properties"/>
<property name= "DataSource" ref= "DataSource"/>
<property name= "Overwriteexistingjobs" value= "true"/>
<property name= "Autostartup" value= "false"/>
</bean>
This bean creates a Schedulerfactorybean instance when spring starts, and it creates a schedule instance based on the properties of your configuration.
Quartz basic configuration, registration thread pool settings, maximum number of connections, etc.
<property name= "configlocation" value= "/web-inf/classes/quartz.properties"/>
You need to use the JDBC store to persist storage, which is explained in detail later
<property name= "DataSource" ref= "DataSource"/>
Need to overwrite the existing job, if you need to dynamically modify the existing job, you need to set to true, otherwise it will be in the database already exist in the
<property name= "Overwriteexistingjobs" value= "true"/>
Whether it starts automatically, this is a better understanding
<property name= "Autostartup" value= "true"/>
4. How to configure JDBC persistence for quartz.
The quartz itself provides two ways to do JDBC persistence. One is in the quartz.properties you configure, specifically can refer to its example.
The other is to configure Schedulerfactorybean's DataSource property in spring, you need to create a DataSource bean in spring.
<bean id= "DataSource" class= "Org.apache.commons.dbcp.BasicDataSource" destroy-method= "Close" >
<property name= "Driverclassname" ><value>org.postgresql.Driver</value></property>
<property name= "url" ><value>jdbc:postgresql://127.0.0.1:3306/dms</value></property>
<property name= "username" ><value>username</value></property>
<property name= "Password" ><value>password</value></property>
</bean>
I am in use, the first way, has not been successful, unable to connect to the database, check for various reasons, or did not find root cause.
But the second way, without any problems.
This article transferred from: http://www.cnblogs.com/jamesmile/p/3871503.html
Quartz integration with spring