org.quartz.SchedulerConfigException Java Examples

The following examples show how to use org.quartz.SchedulerConfigException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JobStoreCMT.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void initialize(ClassLoadHelper loadHelper,
        SchedulerSignaler signaler) throws SchedulerConfigException {

    if (nonManagedTxDsName == null) {
        throw new SchedulerConfigException(
            "Non-ManagedTX DataSource name not set!  " +
            "If your 'org.quartz.jobStore.dataSource' is XA, then set " + 
            "'org.quartz.jobStore.nonManagedTXDataSource' to a non-XA "+ 
            "datasource (for the same DB).  " + 
            "Otherwise, you can set them to be the same.");
    }

    if (getLockHandler() == null) {
        // If the user hasn't specified an explicit lock handler, 
        // then we *must* use DB locks with CMT...
        setUseDBLocks(true);
    }

    super.initialize(loadHelper, signaler);

    getLog().info("JobStoreCMT initialized.");
}
 
Example #2
Source File: JobStoreSupport.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @see org.quartz.spi.JobStore#schedulerStarted()
 */
public void schedulerStarted() throws SchedulerException {

    if (isClustered()) {
        clusterManagementThread = new ClusterManager();
        if(initializersLoader != null)
            clusterManagementThread.setContextClassLoader(initializersLoader);
        clusterManagementThread.initialize();
    } else {
        try {
            recoverJobs();
        } catch (SchedulerException se) {
            throw new SchedulerConfigException(
                    "Failure occured during job recovery.", se);
        }
    }

    misfireHandler = new MisfireHandler();
    if(initializersLoader != null)
        misfireHandler.setContextClassLoader(initializersLoader);
    misfireHandler.initialize();
    schedulerRunning = true;
    
    getLog().debug("JobStore background threads started (as scheduler was started).");
}
 
Example #3
Source File: JobStoreSupport.java    From AsuraFramework with Apache License 2.0 6 votes vote down vote up
/**
 * @see org.quartz.spi.JobStore#schedulerStarted()
 */
public void schedulerStarted() throws SchedulerException {

    if (isClustered()) {
        clusterManagementThread = new ClusterManager();
        if(initializersLoader != null)
        	clusterManagementThread.setContextClassLoader(initializersLoader);
        clusterManagementThread.initialize();
    } else {
        try {
            recoverJobs();
        } catch (SchedulerException se) {
            throw new SchedulerConfigException(
                    "Failure occured during job recovery.", se);
        }
    }

    misfireHandler = new MisfireHandler();
    if(initializersLoader != null)
    	misfireHandler.setContextClassLoader(initializersLoader);
    misfireHandler.initialize();
}
 
Example #4
Source File: JobStoreCMT.java    From AsuraFramework with Apache License 2.0 6 votes vote down vote up
public void initialize(ClassLoadHelper loadHelper,
        SchedulerSignaler signaler) throws SchedulerConfigException {

    if (nonManagedTxDsName == null) {
        throw new SchedulerConfigException(
            "Non-ManagedTX DataSource name not set!  " +
            "If your 'org.quartz.jobStore.dataSource' is XA, then set " + 
            "'org.quartz.jobStore.nonManagedTXDataSource' to a non-XA "+ 
            "datasource (for the same DB).  " + 
            "Otherwise, you can set them to be the same.");
    }

    if (getLockHandler() == null) {
        // If the user hasn't specified an explicit lock handler, 
        // then we *must* use DB locks with CMT...
        setUseDBLocks(true);
    }

    super.initialize(loadHelper, signaler);

    getLog().info("JobStoreCMT initialized.");
}
 
Example #5
Source File: QuartzService.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void stopService() throws Exception {
    log.info("Stop QuartzService(" + jndiName + ")...");

    try {
        Scheduler scheduler = schedulerFactory.getScheduler();

        scheduler.shutdown();
    } catch (Exception e) {
        log.error("Failed to shutdown Scheduler", e);

        throw new SchedulerConfigException(
                "Failed to shutdown Scheduler - ", e);
    }

    unbind(jndiName);

    log.info("QuartzService(" + jndiName + ") stopped.");
}
 
Example #6
Source File: QuartzService.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void setJndiName(String jndiName) throws Exception {
    String oldName = this.jndiName;
    this.jndiName = jndiName;

    if (super.getState() == STARTED) {
        unbind(oldName);

        try {
            rebind();
        } catch (NamingException ne) {
            log.error("Failed to rebind Scheduler", ne);

            throw new SchedulerConfigException(
                    "Failed to rebind Scheduler - ", ne);
        }
    }
}
 
Example #7
Source File: PlainTerracottaJobStore.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public synchronized void initialize(ClassLoadHelper loadHelper, SchedulerSignaler signaler)
    throws SchedulerConfigException {
  if (clusteredJobStore != null) { throw new IllegalStateException("already initialized"); }

  clusteredJobStore = createNewJobStoreInstance(schedName, Boolean.valueOf(synchWrite));
  clusteredJobStore.setThreadPoolSize(threadPoolSize);

  // apply deferred misfire threshold if present
  if (misfireThreshold != null) {
    clusteredJobStore.setMisfireThreshold(misfireThreshold);
    misfireThreshold = null;
  }

  if (estimatedTimeToReleaseAndAcquireTrigger != null) {
    clusteredJobStore.setEstimatedTimeToReleaseAndAcquireTrigger(estimatedTimeToReleaseAndAcquireTrigger);
    estimatedTimeToReleaseAndAcquireTrigger = null;
  }
  clusteredJobStore.setInstanceId(schedInstanceId);
  clusteredJobStore.setTcRetryInterval(tcRetryInterval);
  clusteredJobStore.initialize(loadHelper, signaler);

  // update check
  scheduleUpdateCheck();
}
 
Example #8
Source File: AbstractTerracottaJobStore.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void initialize(ClassLoadHelper loadHelper, SchedulerSignaler signaler) throws SchedulerConfigException {
  init();
  realJobStore.setInstanceId(schedInstId);
  realJobStore.setInstanceName(schedName);
  realJobStore.setTcRetryInterval(tcRetryInterval);

  if (misFireThreshold != null) {
    realJobStore.setMisfireThreshold(misFireThreshold);
  }

  if (synchWrite != null) {
    realJobStore.setSynchronousWrite(synchWrite);
  }

  if (estimatedTimeToReleaseAndAcquireTrigger != null) {
    realJobStore.setEstimatedTimeToReleaseAndAcquireTrigger(estimatedTimeToReleaseAndAcquireTrigger);
  }

  realJobStore.initialize(loadHelper, signaler);
}
 
Example #9
Source File: QuartzService.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void createService() throws Exception {
    log.info("Create QuartzService(" + jndiName + ")...");

    if (error) {
        log
                .error("Must specify only one of 'Properties' or 'PropertiesFile'");

        throw new Exception(
                "Must specify only one of 'Properties' or 'PropertiesFile'");
    }

    schedulerFactory = new StdSchedulerFactory();

    try {
        if (useProperties) {
            schedulerFactory.initialize(properties);
        }

        if (usePropertiesFile) {
            schedulerFactory.initialize(propertiesFile);
        }
    } catch (Exception e) {
        log.error("Failed to initialize Scheduler", e);

        throw new SchedulerConfigException(
                "Failed to initialize Scheduler - ", e);
    }

    log.info("QuartzService(" + jndiName + ") created.");
}
 
Example #10
Source File: JobStoreTX.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void initialize(ClassLoadHelper classLoadHelper,
        SchedulerSignaler schedSignaler) throws SchedulerConfigException {

    super.initialize(classLoadHelper, schedSignaler);

    getLog().info("JobStoreTX initialized.");
}
 
Example #11
Source File: StdSchedulerFactory.java    From AsuraFramework with Apache License 2.0 5 votes vote down vote up
private Class loadClass(String className) throws ClassNotFoundException, SchedulerConfigException {

        try {
            ClassLoader cl = findClassloader();
            if(cl != null)
                return cl.loadClass(className);
            throw new SchedulerConfigException("Unable to find a class loader on the current thread or class.");
        } catch (ClassNotFoundException e) {
            if(getClass().getClassLoader() != null)
                return getClass().getClassLoader().loadClass(className);
            throw e;
        }
    }
 
Example #12
Source File: QuartzService.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void startService() throws Exception {
    log.info("Start QuartzService(" + jndiName + ")...");

    try {
        rebind();
    } catch (NamingException ne) {
        log.error("Failed to rebind Scheduler", ne);

        throw new SchedulerConfigException("Failed to rebind Scheduler - ",
                ne);
    }

    try {
        Scheduler scheduler = schedulerFactory.getScheduler();

        if (startScheduler) {
            scheduler.start();
        } else {
            log.info("Skipping starting the scheduler (will not run jobs).");
        }
    } catch (Exception e) {
        log.error("Failed to start Scheduler", e);

        throw new SchedulerConfigException("Failed to start Scheduler - ",
                e);
    }

    log.info("QuartzService(" + jndiName + ") started.");
}
 
Example #13
Source File: AbstractTerracottaJobStore.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void init() throws SchedulerConfigException {
  if (realJobStore != null) { return; }

  if ((tcConfig != null) && (tcConfigUrl != null)) {
    //
    throw new SchedulerConfigException("Both " + TC_CONFIG_PROP + " and " + TC_CONFIGURL_PROP
                                       + " are set in your properties. Please define only one of them");
  }

  if ((tcConfig == null) && (tcConfigUrl == null)) {
    //
    throw new SchedulerConfigException("Neither " + TC_CONFIG_PROP + " or " + TC_CONFIGURL_PROP
                                       + " are set in your properties. Please define one of them");
  }

  final boolean isURLConfig = tcConfig == null;
  TerracottaToolkitBuilder toolkitBuilder = new TerracottaToolkitBuilder();
  if (isURLConfig) {
    toolkitBuilder.setTCConfigUrl(tcConfigUrl);
  } else {
    toolkitBuilder.setTCConfigSnippet(tcConfig);
  }
  if (rejoin != null) {
    toolkitBuilder.setRejoin(rejoin);
  }
  toolkitBuilder.addTunnelledMBeanDomain("quartz");
  toolkit = (ToolkitInternal) toolkitBuilder.buildToolkit();

  try {
    realJobStore = getRealStore(toolkit);
  } catch (Exception e) {
    throw new SchedulerConfigException("Unable to create Terracotta client", e);
  }
}
 
Example #14
Source File: LocalTaskExecutorThreadPool.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void initialize() throws SchedulerConfigException {
	// Absolutely needs thread-bound TaskExecutor to initialize.
	this.taskExecutor = SchedulerFactoryBean.getConfigTimeTaskExecutor();
	if (this.taskExecutor == null) {
		throw new SchedulerConfigException(
			"No local TaskExecutor found for configuration - " +
			"'taskExecutor' property must be set on SchedulerFactoryBean");
	}
}
 
Example #15
Source File: LocalTaskExecutorThreadPool.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize() throws SchedulerConfigException {
	// Absolutely needs thread-bound TaskExecutor to initialize.
	this.taskExecutor = SchedulerFactoryBean.getConfigTimeTaskExecutor();
	if (this.taskExecutor == null) {
		throw new SchedulerConfigException(
			"No local TaskExecutor found for configuration - " +
			"'taskExecutor' property must be set on SchedulerFactoryBean");
	}
}
 
Example #16
Source File: LocalTaskExecutorThreadPool.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void initialize() throws SchedulerConfigException {
	// Absolutely needs thread-bound Executor to initialize.
	this.taskExecutor = SchedulerFactoryBean.getConfigTimeTaskExecutor();
	if (this.taskExecutor == null) {
		throw new SchedulerConfigException("No local Executor found for configuration - " +
				"'taskExecutor' property must be set on SchedulerFactoryBean");
	}
}
 
Example #17
Source File: JobStoreImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void initialize(final ClassLoadHelper loadHelper, final SchedulerSignaler signaler)
    throws SchedulerConfigException
{
  log.info("Instance name: {}; ID: {}", instanceName, instanceId);

  // TODO: Should we consider using ClassLoadHelper?
  this.signaler = checkNotNull(signaler);

  log.info("Initialized");
}
 
Example #18
Source File: LocalTaskExecutorThreadPool.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void initialize() throws SchedulerConfigException {
	// Absolutely needs thread-bound Executor to initialize.
	this.taskExecutor = SchedulerFactoryBean.getConfigTimeTaskExecutor();
	if (this.taskExecutor == null) {
		throw new SchedulerConfigException("No local Executor found for configuration - " +
				"'taskExecutor' property must be set on SchedulerFactoryBean");
	}
}
 
Example #19
Source File: LocalDataSourceJobStore.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize(ClassLoadHelper loadHelper, SchedulerSignaler signaler)
		throws SchedulerConfigException {

	// Absolutely needs thread-bound DataSource to initialize.
	this.dataSource = SchedulerFactoryBean.getConfigTimeDataSource();
	if (this.dataSource == null) {
		throw new SchedulerConfigException(
			"No local DataSource found for configuration - " +
			"'dataSource' property must be set on SchedulerFactoryBean");
	}

	// Configure transactional connection settings for Quartz.
	setDataSource(TX_DATA_SOURCE_PREFIX + getInstanceName());
	setDontSetAutoCommitFalse(true);

	// Register transactional ConnectionProvider for Quartz.
	DBConnectionManager.getInstance().addConnectionProvider(
			TX_DATA_SOURCE_PREFIX + getInstanceName(),
			new ConnectionProvider() {
				@Override
				public Connection getConnection() throws SQLException {
					// Return a transactional Connection, if any.
					return DataSourceUtils.doGetConnection(dataSource);
				}
				@Override
				public void shutdown() {
					// Do nothing - a Spring-managed DataSource has its own lifecycle.
				}
				/* Quartz 2.2 initialize method */
				public void initialize() {
					// Do nothing - a Spring-managed DataSource has its own lifecycle.
				}
			}
	);

	// Non-transactional DataSource is optional: fall back to default
	// DataSource if not explicitly specified.
	DataSource nonTxDataSource = SchedulerFactoryBean.getConfigTimeNonTransactionalDataSource();
	final DataSource nonTxDataSourceToUse = (nonTxDataSource != null ? nonTxDataSource : this.dataSource);

	// Configure non-transactional connection settings for Quartz.
	setNonManagedTXDataSource(NON_TX_DATA_SOURCE_PREFIX + getInstanceName());

	// Register non-transactional ConnectionProvider for Quartz.
	DBConnectionManager.getInstance().addConnectionProvider(
			NON_TX_DATA_SOURCE_PREFIX + getInstanceName(),
			new ConnectionProvider() {
				@Override
				public Connection getConnection() throws SQLException {
					// Always return a non-transactional Connection.
					return nonTxDataSourceToUse.getConnection();
				}
				@Override
				public void shutdown() {
					// Do nothing - a Spring-managed DataSource has its own lifecycle.
				}
				/* Quartz 2.2 initialize method */
				public void initialize() {
					// Do nothing - a Spring-managed DataSource has its own lifecycle.
				}
			}
	);

	// No, if HSQL is the platform, we really don't want to use locks...
	try {
		String productName = JdbcUtils.extractDatabaseMetaData(this.dataSource, "getDatabaseProductName").toString();
		productName = JdbcUtils.commonDatabaseName(productName);
		if (productName != null && productName.toLowerCase().contains("hsql")) {
			setUseDBLocks(false);
			setLockHandler(new SimpleSemaphore());
		}
	}
	catch (MetaDataAccessException ex) {
		logWarnIfNonZero(1, "Could not detect database type. Assuming locks can be taken.");
	}

	super.initialize(loadHelper, signaler);

}
 
Example #20
Source File: JobStoreSupport.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * <p>
 * Called by the QuartzScheduler before the <code>JobStore</code> is
 * used, in order to give it a chance to initialize.
 * </p>
 */
public void initialize(ClassLoadHelper loadHelper,
        SchedulerSignaler signaler) throws SchedulerConfigException {

    if (dsName == null) { 
        throw new SchedulerConfigException("DataSource name not set."); 
    }

    classLoadHelper = loadHelper;
    if(isThreadsInheritInitializersClassLoadContext()) {
        log.info("JDBCJobStore threads will inherit ContextClassLoader of thread: " + Thread.currentThread().getName());
        initializersLoader = Thread.currentThread().getContextClassLoader();
    }
    
    this.schedSignaler = signaler;

    // If the user hasn't specified an explicit lock handler, then 
    // choose one based on CMT/Clustered/UseDBLocks.
    if (getLockHandler() == null) {
        
        // If the user hasn't specified an explicit lock handler, 
        // then we *must* use DB locks with clustering
        if (isClustered()) {
            setUseDBLocks(true);
        }
        
        if (getUseDBLocks()) {
            if(getDriverDelegateClass() != null && getDriverDelegateClass().equals(MSSQLDelegate.class.getName())) {
                if(getSelectWithLockSQL() == null) {
                    String msSqlDflt = "SELECT * FROM {0}LOCKS WITH (UPDLOCK,ROWLOCK) WHERE " + COL_SCHEDULER_NAME + " = {1} AND LOCK_NAME = ?";
                    getLog().info("Detected usage of MSSQLDelegate class - defaulting 'selectWithLockSQL' to '" + msSqlDflt + "'.");
                    setSelectWithLockSQL(msSqlDflt);
                }
            }
            getLog().info("Using db table-based data access locking (synchronization).");
            setLockHandler(new StdRowLockSemaphore(getTablePrefix(), getInstanceName(), getSelectWithLockSQL()));
        } else {
            getLog().info(
                "Using thread monitor-based data access locking (synchronization).");
            setLockHandler(new SimpleSemaphore());
        }
    }

}
 
Example #21
Source File: SimpleThreadPoolTaskExecutor.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public void afterPropertiesSet() throws SchedulerConfigException {
	initialize();
}
 
Example #22
Source File: StdSchedulerFactory.java    From AsuraFramework with Apache License 2.0 4 votes vote down vote up
private void setBeanProps(Object obj, Properties props)
    throws NoSuchMethodException, IllegalAccessException,
        java.lang.reflect.InvocationTargetException,
        IntrospectionException, SchedulerConfigException {
    props.remove("class");

    BeanInfo bi = Introspector.getBeanInfo(obj.getClass());
    PropertyDescriptor[] propDescs = bi.getPropertyDescriptors();
    PropertiesParser pp = new PropertiesParser(props);

    java.util.Enumeration keys = props.keys();
    while (keys.hasMoreElements()) {
        String name = (String) keys.nextElement();
        String c = name.substring(0, 1).toUpperCase(Locale.US);
        String methName = "set" + c + name.substring(1);

        java.lang.reflect.Method setMeth = getSetMethod(methName, propDescs);

        try {
            if (setMeth == null) {
                throw new NoSuchMethodException(
                        "No setter for property '" + name + "'");
            }

            Class[] params = setMeth.getParameterTypes();
            if (params.length != 1) {
                throw new NoSuchMethodException(
                    "No 1-argument setter for property '" + name + "'");
            }
            
            // does the property value reference another property's value? If so, swap to look at its value
            PropertiesParser refProps = pp;
            String refName = pp.getStringProperty(name);
            if(refName != null && refName.startsWith("$@")) {
                refName =  refName.substring(2);
                refProps = cfg;
            }
            else
                refName = name;
            
            if (params[0].equals(int.class)) {
                setMeth.invoke(obj, new Object[]{new Integer(refProps.getIntProperty(refName))});
            } else if (params[0].equals(long.class)) {
                setMeth.invoke(obj, new Object[]{new Long(refProps.getLongProperty(refName))});
            } else if (params[0].equals(float.class)) {
                setMeth.invoke(obj, new Object[]{new Float(refProps.getFloatProperty(refName))});
            } else if (params[0].equals(double.class)) {
                setMeth.invoke(obj, new Object[]{new Double(refProps.getDoubleProperty(refName))});
            } else if (params[0].equals(boolean.class)) {
                setMeth.invoke(obj, new Object[]{new Boolean(refProps.getBooleanProperty(refName))});
            } else if (params[0].equals(String.class)) {
                setMeth.invoke(obj, new Object[]{refProps.getStringProperty(refName)});
            } else {
                throw new NoSuchMethodException(
                        "No primitive-type setter for property '" + name
                                + "'");
            }
        } catch (NumberFormatException nfe) {
            throw new SchedulerConfigException("Could not parse property '"
                    + name + "' into correct data type: " + nfe.toString());
        }
    }
}
 
Example #23
Source File: JobStoreSupport.java    From AsuraFramework with Apache License 2.0 4 votes vote down vote up
/**
 * <p>
 * Called by the QuartzScheduler before the <code>JobStore</code> is
 * used, in order to give it a chance to initialize.
 * </p>
 */
public void initialize(ClassLoadHelper loadHelper,
        SchedulerSignaler signaler) throws SchedulerConfigException {

    if (dsName == null) { 
        throw new SchedulerConfigException("DataSource name not set."); 
    }

    classLoadHelper = loadHelper;
    if(isThreadsInheritInitializersClassLoadContext()) {
    	log.info("JDBCJobStore threads will inherit ContextClassLoader of thread: " + Thread.currentThread().getName());
    	initializersLoader = Thread.currentThread().getContextClassLoader();
    }
    
    this.schedSignaler = signaler;

    // If the user hasn't specified an explicit lock handler, then 
    // choose one based on CMT/Clustered/UseDBLocks.
    if (getLockHandler() == null) {
        
        // If the user hasn't specified an explicit lock handler, 
        // then we *must* use DB locks with clustering
        if (isClustered()) {
            setUseDBLocks(true);
        }
        
        if (getUseDBLocks()) {
            if(getDriverDelegateClass() != null && getDriverDelegateClass().equals(MSSQLDelegate.class.getName())) {
                if(getSelectWithLockSQL() == null) {
                    String msSqlDflt = "SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?";
                    getLog().info("Detected usage of MSSQLDelegate class - defaulting 'selectWithLockSQL' to '" + msSqlDflt + "'.");
                    setSelectWithLockSQL(msSqlDflt);
                }
            }
            getLog().info("Using db table-based data access locking (synchronization).");
            setLockHandler(new StdRowLockSemaphore(getTablePrefix(), getSelectWithLockSQL()));
        } else {
            getLog().info(
                "Using thread monitor-based data access locking (synchronization).");
            setLockHandler(new SimpleSemaphore());
        }
    }

    if (!isClustered()) {
        try {
            cleanVolatileTriggerAndJobs();
        } catch (SchedulerException se) {
            throw new SchedulerConfigException(
                    "Failure occured during job recovery.", se);
        }
    }
}
 
Example #24
Source File: SimpleTimeBroker.java    From AsuraFramework with Apache License 2.0 4 votes vote down vote up
public void initialize() throws SchedulerConfigException {
    // do nothing...
}
 
Example #25
Source File: ZeroSizeThreadPool.java    From AsuraFramework with Apache License 2.0 4 votes vote down vote up
public void initialize() throws SchedulerConfigException {
}
 
Example #26
Source File: SimpleThreadPool.java    From AsuraFramework with Apache License 2.0 4 votes vote down vote up
public void initialize() throws SchedulerConfigException {

        if(workers != null && workers.size() > 0) // already initialized...
            return;
        
        if (count <= 0) {
            throw new SchedulerConfigException(
                    "Thread count must be > 0");
        }
        if (prio <= 0 || prio > 9) {
            throw new SchedulerConfigException(
                    "Thread priority must be > 0 and <= 9");
        }

        if(isThreadsInheritGroupOfInitializingThread()) {
            threadGroup = Thread.currentThread().getThreadGroup();
        } else {
            // follow the threadGroup tree to the root thread group.
            threadGroup = Thread.currentThread().getThreadGroup();
            ThreadGroup parent = threadGroup;
            while ( !parent.getName().equals("main") ) {
                threadGroup = parent;
                parent = threadGroup.getParent();
            }
            threadGroup = new ThreadGroup(parent, schedulerInstanceName + "-SimpleThreadPool");
            if (isMakeThreadsDaemons()) {
                threadGroup.setDaemon(true);
            }
        }


        if (isThreadsInheritContextClassLoaderOfInitializingThread()) {
            getLog().info(
                    "Job execution threads will use class loader of thread: "
                            + Thread.currentThread().getName());
        }

        // create the worker threads and start them
        Iterator workerThreads = createWorkerThreads(count).iterator();
        while(workerThreads.hasNext()) {
            WorkerThread wt = (WorkerThread) workerThreads.next();
            wt.start();
            availWorkers.add(wt);
        }
    }
 
Example #27
Source File: QuartzThreadPool.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void initialize() throws SchedulerConfigException {
  // nop
}
 
Example #28
Source File: QuartzCachedThreadPool.java    From carbon-commons with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize() throws SchedulerConfigException {
    this.executor = Executors.newCachedThreadPool();
}
 
Example #29
Source File: SimpleThreadPool.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public void initialize() throws SchedulerConfigException {

        if(workers != null && workers.size() > 0) // already initialized...
            return;
        
        if (count <= 0) {
            throw new SchedulerConfigException(
                    "Thread count must be > 0");
        }
        if (prio <= 0 || prio > 9) {
            throw new SchedulerConfigException(
                    "Thread priority must be > 0 and <= 9");
        }

        if(isThreadsInheritGroupOfInitializingThread()) {
            threadGroup = Thread.currentThread().getThreadGroup();
        } else {
            // follow the threadGroup tree to the root thread group.
            threadGroup = Thread.currentThread().getThreadGroup();
            ThreadGroup parent = threadGroup;
            while ( !parent.getName().equals("main") ) {
                threadGroup = parent;
                parent = threadGroup.getParent();
            }
            threadGroup = new ThreadGroup(parent, schedulerInstanceName + "-SimpleThreadPool");
            if (isMakeThreadsDaemons()) {
                threadGroup.setDaemon(true);
            }
        }


        if (isThreadsInheritContextClassLoaderOfInitializingThread()) {
            getLog().info(
                    "Job execution threads will use class loader of thread: "
                            + Thread.currentThread().getName());
        }

        // create the worker threads and start them
        Iterator<WorkerThread> workerThreads = createWorkerThreads(count).iterator();
        while(workerThreads.hasNext()) {
            WorkerThread wt = workerThreads.next();
            wt.start();
            availWorkers.add(wt);
        }
    }
 
Example #30
Source File: LocalDataSourceJobStore.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public void initialize(ClassLoadHelper loadHelper, SchedulerSignaler signaler) throws SchedulerConfigException {
	// Absolutely needs thread-bound DataSource to initialize.
	this.dataSource = SchedulerFactoryBean.getConfigTimeDataSource();
	if (this.dataSource == null) {
		throw new SchedulerConfigException("No local DataSource found for configuration - " +
				"'dataSource' property must be set on SchedulerFactoryBean");
	}

	// Configure transactional connection settings for Quartz.
	setDataSource(TX_DATA_SOURCE_PREFIX + getInstanceName());
	setDontSetAutoCommitFalse(true);

	// Register transactional ConnectionProvider for Quartz.
	DBConnectionManager.getInstance().addConnectionProvider(
			TX_DATA_SOURCE_PREFIX + getInstanceName(),
			new ConnectionProvider() {
				@Override
				public Connection getConnection() throws SQLException {
					// Return a transactional Connection, if any.
					return DataSourceUtils.doGetConnection(dataSource);
				}
				@Override
				public void shutdown() {
					// Do nothing - a Spring-managed DataSource has its own lifecycle.
				}
				/* Quartz 2.2 initialize method */
				public void initialize() {
					// Do nothing - a Spring-managed DataSource has its own lifecycle.
				}
			}
	);

	// Non-transactional DataSource is optional: fall back to default
	// DataSource if not explicitly specified.
	DataSource nonTxDataSource = SchedulerFactoryBean.getConfigTimeNonTransactionalDataSource();
	final DataSource nonTxDataSourceToUse = (nonTxDataSource != null ? nonTxDataSource : this.dataSource);

	// Configure non-transactional connection settings for Quartz.
	setNonManagedTXDataSource(NON_TX_DATA_SOURCE_PREFIX + getInstanceName());

	// Register non-transactional ConnectionProvider for Quartz.
	DBConnectionManager.getInstance().addConnectionProvider(
			NON_TX_DATA_SOURCE_PREFIX + getInstanceName(),
			new ConnectionProvider() {
				@Override
				public Connection getConnection() throws SQLException {
					// Always return a non-transactional Connection.
					return nonTxDataSourceToUse.getConnection();
				}
				@Override
				public void shutdown() {
					// Do nothing - a Spring-managed DataSource has its own lifecycle.
				}
				/* Quartz 2.2 initialize method */
				public void initialize() {
					// Do nothing - a Spring-managed DataSource has its own lifecycle.
				}
			}
	);

	// No, if HSQL is the platform, we really don't want to use locks...
	try {
		String productName = JdbcUtils.extractDatabaseMetaData(this.dataSource, "getDatabaseProductName");
		productName = JdbcUtils.commonDatabaseName(productName);
		if (productName != null && productName.toLowerCase().contains("hsql")) {
			setUseDBLocks(false);
			setLockHandler(new SimpleSemaphore());
		}
	}
	catch (MetaDataAccessException ex) {
		logWarnIfNonZero(1, "Could not detect database type. Assuming locks can be taken.");
	}

	super.initialize(loadHelper, signaler);

}