Example usage for org.springframework.scheduling.concurrent ThreadPoolTaskExecutor setAwaitTerminationSeconds

List of usage examples for org.springframework.scheduling.concurrent ThreadPoolTaskExecutor setAwaitTerminationSeconds

Introduction

In this page you can find the example usage for org.springframework.scheduling.concurrent ThreadPoolTaskExecutor setAwaitTerminationSeconds.

Prototype

public void setAwaitTerminationSeconds(int awaitTerminationSeconds) 

Source Link

Document

Set the maximum number of seconds that this executor is supposed to block on shutdown in order to wait for remaining tasks to complete their execution before the rest of the container continues to shut down.

Usage

From source file:com.teradata.benchto.driver.DriverApp.java

@Bean
public ThreadPoolTaskExecutor defaultTaskExecutor() {
    ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
    taskExecutor.setMaxPoolSize(5);//from   w  w w .j  a  va2s.co m
    taskExecutor.setWaitForTasksToCompleteOnShutdown(true);
    taskExecutor.setAwaitTerminationSeconds(300);

    return taskExecutor;
}

From source file:com.ethlo.geodata.GeodataServiceImpl.java

public void load() {
    ensureBaseDirectory();//  ww w  . j  a va  2  s  .  co m

    final SourceDataInfoSet sourceInfo = geoMetaService.getSourceDataInfo();
    if (sourceInfo.isEmpty()) {
        logger.error(
                "Cannot start geodata server as there is no data. Please run with 'update' parameter to import data");
        System.exit(1);
    }

    loadHierarchy();

    final ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
    taskExecutor.setCorePoolSize(3);
    taskExecutor.setThreadNamePrefix("data-loading-");
    taskExecutor.initialize();

    taskExecutor.execute(this::loadLocations);
    taskExecutor.execute(this::loadMbr);
    taskExecutor.execute(this::loadIps);

    taskExecutor.setAwaitTerminationSeconds(Integer.MAX_VALUE);
    taskExecutor.setWaitForTasksToCompleteOnShutdown(true);
    taskExecutor.shutdown();

    //final ResultSet<GeoLocation> result = geoNamesRepository.retrieve(QueryFactory.equal(CqGeonamesRepository.ATTRIBUTE_FEATURE_CODE, "ADM1"));
    //result.forEach(this::connectAdm1WithCountry);

    publisher.publishEvent(new DataLoadedEvent(this, DataType.ALL, Operation.LOAD, 1, 1));
}