首页 > 代码库 > springquartz的LocalDataSourceJobStore

springquartz的LocalDataSourceJobStore

spring 为quartz 提供了一个 继承 JobStoreCMT的 LocalDataSourceJobStore,主要是为了和spring更好的集成。

public class LocalDataSourceJobStore extends JobStoreCMT {	/**	 * Name used for the transactional ConnectionProvider for Quartz.	 * This provider will delegate to the local Spring-managed DataSource.	 * @see org.quartz.utils.DBConnectionManager#addConnectionProvider	 * @see SchedulerFactoryBean#setDataSource	 */	public static final String TX_DATA_SOURCE_PREFIX = "springTxDataSource.";
 
这里有一个非常关键地方
setDontSetAutoCommitFalse(true);
//表明是将connection自动提交打开。// Register transactional ConnectionProvider for Quartz.DBConnectionManager.getInstance().addConnectionProvider(	TX_DATA_SOURCE_PREFIX + getInstanceName(),	new ConnectionProvider() {	   public Connection getConnection() throws SQLException {		// Return a transactional Connection, if any.		return DataSourceUtils.doGetConnection(dataSource);	}	public void shutdown() {	// Do nothing - a Spring-managed DataSource has its own lifecycle.	}    });
 
如何使用:
如果你在spring的配置文件中使用SchedulerFactoryBean配置了datasoucrce,即使用spring托管的datasource,则spring会强制使用这个jobstore、LocalDataSourceJobStore

springquartz的LocalDataSourceJobStore