Example usage for org.springframework.scheduling.quartz SchedulerFactoryBean setApplicationContextSchedulerContextKey

List of usage examples for org.springframework.scheduling.quartz SchedulerFactoryBean setApplicationContextSchedulerContextKey

Introduction

In this page you can find the example usage for org.springframework.scheduling.quartz SchedulerFactoryBean setApplicationContextSchedulerContextKey.

Prototype

public void setApplicationContextSchedulerContextKey(String applicationContextSchedulerContextKey) 

Source Link

Document

Set the key of an ApplicationContext reference to expose in the SchedulerContext, for example "applicationContext".

Usage

From source file:com.github.dbourdette.glass.SpringConfig.java

@Bean
public Scheduler quartzScheduler(ApplicationContext context) throws Exception {
    SchedulerFactoryBean factory = new SchedulerFactoryBean();

    factory.setApplicationContext(context);
    factory.setExposeSchedulerInRepository(true);
    factory.setApplicationContextSchedulerContextKey(APPLICATION_CONTEXT_KEY);
    factory.setJobFactory(glassJobFactory);

    Properties properties = new Properties();
    properties.setProperty("org.quartz.threadPool.class", SimpleThreadPool.class.getName());
    properties.setProperty("org.quartz.threadPool.threadCount", "15");
    properties.setProperty("org.quartz.threadPool.threadPriority", "4");

    if (configuration().isInMemory()) {
        properties.setProperty("org.quartz.jobStore.class", RAMJobStore.class.getName());
    } else {/* ww w . j a v a  2  s .c  om*/
        factory.setDataSource(dataSource());

        properties.setProperty("org.quartz.jobStore.tablePrefix", configuration().getTablePrefix());
        properties.setProperty("org.quartz.jobStore.isClustered", "false");
        properties.setProperty("org.quartz.jobStore.driverDelegateClass",
                configuration().getDriverDelegateClass());
    }

    factory.setQuartzProperties(properties);

    factory.afterPropertiesSet();

    Scheduler scheduler = factory.getObject();

    scheduler.getListenerManager().addJobListener(glassJobListener);
    scheduler.getListenerManager().addSchedulerListener(glassSchedulerListener);

    scheduler.start();

    return scheduler;
}