Example usage for org.springframework.scheduling.concurrent ThreadPoolTaskScheduler initialize

List of usage examples for org.springframework.scheduling.concurrent ThreadPoolTaskScheduler initialize

Introduction

In this page you can find the example usage for org.springframework.scheduling.concurrent ThreadPoolTaskScheduler initialize.

Prototype

public void initialize() 

Source Link

Document

Set up the ExecutorService.

Usage

From source file:com.emo.ananas.app.App.java

public static void main(String[] args) throws InterruptedException {
    final ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();

    Config config = ConfigFactory.load();

    Preconditions.checkArgument(config.hasPath("emailer"), "expected an 'emailer' object in config");
    final Config emailerConfig = config.getConfig("emailer");
    Preconditions.checkArgument(emailerConfig.hasPath("smtp"), "expected emailer.smtp in config");

    EmailSenderConfig emailSenderConfig = new EmailSenderConfig(emailerConfig.getString("smtp"));

    Preconditions.checkArgument(config.hasPath("reports"), "expected reports object in config");
    final Config reportsConfig = config.getConfig("reports");
    Preconditions.checkArgument(reportsConfig.hasPath("actives"),
            "expected reports.actives with array of active declared reports in config");
    final List<String> activeReports = reportsConfig.getStringList("actives");

    final DataSourceFactory factory = new DataSourceFactory(config.getConfig("datasources"));

    for (final String activeReport : activeReports) {
        Preconditions.checkArgument(reportsConfig.hasPath(activeReport), "expected reports." + activeReport
                + " in config, because it is declared in actives report list");
    }//from   w w  w. jav a 2s.c  o  m

    scheduler.initialize();

    for (final String activeReport : activeReports) {
        final Config reportConfig = reportsConfig.getConfig(activeReport);
        final CronConfig cronConfig = new CronConfig(reportConfig);
        final EmailConfig emailConfig = new EmailConfig(reportConfig);
        final BaseConfig dataSource = new BaseConfig(reportConfig, factory);
        final QueryConfig queryConfig = new QueryConfig(reportConfig, dataSource.dataSource());
        final Report report = new Report(activeReport, scheduler, emailSenderConfig, emailConfig, cronConfig,
                queryConfig);
        report.schedule();
    }

    while (true) {
        Thread.sleep(60000);
    }
}

From source file:com.joshlong.esb.springintegration.modules.net.sftp.Main.java

static void run(SFTPSessionFactory sftpSessionFactory, String lp, String rp) throws Throwable {
    // local path
    File local = new File(lp); // obviously this is just for test. Do what you need to do in your own

    // we are testing, after all
    if (local.exists() && (local.list().length > 0)) {
        for (File f : local.listFiles()) {
            if (!f.delete()) {
                logger.debug("couldn't delete " + f.getAbsolutePath());
            }/*from   w ww .  ja  v a2  s .com*/
        }
    }

    Resource localDirectory = new FileSystemResource(local);

    // pool
    QueuedSFTPSessionPool queuedSFTPSessionPool = new QueuedSFTPSessionPool(sftpSessionFactory);
    queuedSFTPSessionPool.afterPropertiesSet();

    ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
    taskScheduler.setPoolSize(10);
    taskScheduler.setErrorHandler(new ErrorHandler() {
        public void handleError(Throwable t) {
            logger.debug("error! ", t);
        }
    });

    taskScheduler.setWaitForTasksToCompleteOnShutdown(true);
    taskScheduler.initialize();

    // synchronizer
    final SFTPInboundSynchronizer sftpInboundSynchronizer = new SFTPInboundSynchronizer();
    sftpInboundSynchronizer.setLocalDirectory(localDirectory);
    sftpInboundSynchronizer.setRemotePath(rp);
    sftpInboundSynchronizer.setAutoCreatePath(true);
    sftpInboundSynchronizer.setPool(queuedSFTPSessionPool);
    sftpInboundSynchronizer.setShouldDeleteDownloadedRemoteFiles(false);
    sftpInboundSynchronizer.setTaskScheduler(taskScheduler);
    sftpInboundSynchronizer.afterPropertiesSet();
    sftpInboundSynchronizer.start();

    /*
        new Thread(new Runnable() {
            public void run() {
                try {
                    Thread.sleep(60 * 1000); // 1 minute
            
                    sftpInboundSynchronizer.stop();
            
                } catch (InterruptedException e) {
                    // don't care
                }
            }
        }).start();
    */
}

From source file:com.stratio.streaming.configuration.SchredulerConfiguration.java

@Bean
public TaskScheduler taskScheduler() {
    ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
    taskScheduler.initialize();
    if (configurationContext.isFailOverEnabled()) {
        taskScheduler.scheduleAtFixedRate(failOverTask(), configurationContext.getFailOverPeriod());
    }// w  w  w . ja va 2  s  .  co  m
    return taskScheduler;
}

From source file:com.stratio.decision.clustering.ClusterSyncManagerLeaderListener.java

private void initializeFailOverTask() {

    if (failOverTask != null) {
        ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
        taskScheduler.initialize();

        taskScheduler.scheduleAtFixedRate(failOverTask, 60000);
    }/*from ww w. ja  v a2 s .  c  om*/

}

From source file:com.yoho.core.trace.instrument.web.client.async.TraceAsyncClientHttpRequestFactoryWrapper.java

private AsyncListenableTaskExecutor asyncListenableTaskExecutor(Tracer tracer) {
    ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
    threadPoolTaskScheduler.initialize();
    return new TraceAsyncListenableTaskExecutor(threadPoolTaskScheduler, tracer);
}

From source file:org.deshang.content.indexing.config.SpringConfig.java

@Bean
public TaskScheduler taskScheduler() throws Exception {
    ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
    taskScheduler.setPoolSize(env.getProperty(SCHEDULER_POOL_SIZE, int.class));
    taskScheduler.initialize();
    taskScheduler.schedule(contentIndexingTask(),
            new CronTrigger(env.getProperty(CONTENT_INDEXING_TASK_CRON_EXPRESSION)));
    return taskScheduler;
}

From source file:com.alliander.osgp.acceptancetests.config.SchedulingConfig.java

@Bean
public TaskScheduler taskScheduler() {
    final ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
    taskScheduler.setPoolSize(SCHEDULING_TASK_SCHEDULER_POOL_SIZE);
    taskScheduler.setThreadNamePrefix(SCHEDULING_TASK_SCHEDULER_THREAD_NAME_PREFIX);
    taskScheduler.initialize();
    taskScheduler.schedule(this.scheduledTaskScheduler, this.scheduledTasksCronTrigger());
    return taskScheduler;
}

From source file:io.lavagna.config.PersistenceAndServiceConfig.java

@Bean(destroyMethod = "shutdown")
public TaskScheduler taskScheduler() {
    ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
    scheduler.setErrorHandler(new ErrorHandler() {
        @Override//from   w w  w  .ja va2s.c  o m
        public void handleError(Throwable t) {
            LogManager.getLogger().error("error while handling job", t);
        }
    });
    scheduler.initialize();
    return scheduler;
}

From source file:com.alliander.osgp.webdevicesimulator.application.config.AutonomousDeviceRebootConfig.java

@Bean(destroyMethod = "shutdown")
public TaskScheduler deviceRebootTaskScheduler() {
    final ThreadPoolTaskScheduler deviceRebootTaskScheduler = new ThreadPoolTaskScheduler();
    deviceRebootTaskScheduler.setPoolSize(Integer
            .parseInt(this.environment.getRequiredProperty(PROPERTY_NAME_AUTONOMOUS_DEVICE_REBOOT_POOL_SIZE)));
    deviceRebootTaskScheduler.setThreadNamePrefix(
            this.environment.getRequiredProperty(PROPERTY_NAME_AUTONOMOUS_DEVICE_REBOOT_THREAD_NAME_PREFIX));
    deviceRebootTaskScheduler.setWaitForTasksToCompleteOnShutdown(false);
    deviceRebootTaskScheduler.setAwaitTerminationSeconds(10);
    deviceRebootTaskScheduler.initialize();
    deviceRebootTaskScheduler.schedule(this.autonomousDeviceReboot, this.autonomousDeviceRebootTrigger());
    return deviceRebootTaskScheduler;
}

From source file:com.alliander.osgp.webdevicesimulator.application.config.AutonomousDeviceRegisterConfig.java

@Bean(destroyMethod = "shutdown")
public TaskScheduler deviceRegistrationTaskScheduler() {
    final ThreadPoolTaskScheduler deviceRegistrationTaskScheduler = new ThreadPoolTaskScheduler();
    deviceRegistrationTaskScheduler.setPoolSize(
            Integer.parseInt(this.environment.getRequiredProperty(PROPERTY_NAME_AUTONOMOUS_POOL_SIZE)));
    deviceRegistrationTaskScheduler.setThreadNamePrefix(
            this.environment.getRequiredProperty(PROPERTY_NAME_AUTONOMOUS_THREAD_NAME_PREFIX));
    deviceRegistrationTaskScheduler.setWaitForTasksToCompleteOnShutdown(false);
    deviceRegistrationTaskScheduler.setAwaitTerminationSeconds(10);
    deviceRegistrationTaskScheduler.initialize();
    deviceRegistrationTaskScheduler.schedule(this.autonomousDeviceRegister,
            this.autonomousDeviceRegisterTrigger());
    return deviceRegistrationTaskScheduler;
}