當前位置: 首頁>>代碼示例>>Java>>正文


Java ThreadPoolTaskScheduler.setWaitForTasksToCompleteOnShutdown方法代碼示例

本文整理匯總了Java中org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler.setWaitForTasksToCompleteOnShutdown方法的典型用法代碼示例。如果您正苦於以下問題:Java ThreadPoolTaskScheduler.setWaitForTasksToCompleteOnShutdown方法的具體用法?Java ThreadPoolTaskScheduler.setWaitForTasksToCompleteOnShutdown怎麽用?Java ThreadPoolTaskScheduler.setWaitForTasksToCompleteOnShutdown使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler的用法示例。


在下文中一共展示了ThreadPoolTaskScheduler.setWaitForTasksToCompleteOnShutdown方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: taskScheduler

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //導入方法依賴的package包/類
@Bean
public ThreadPoolTaskScheduler taskScheduler()
{
    logger.info("Setting up thread pool task scheduler with 20 threads.");
    ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
    scheduler.setPoolSize(20);
    scheduler.setThreadNamePrefix("task-");
    scheduler.setAwaitTerminationSeconds(60);
    scheduler.setWaitForTasksToCompleteOnShutdown(true);
    scheduler.setErrorHandler(t -> schedulingLogger.error(
            "Unknown error occurred while executing task.", t
    ));
    scheduler.setRejectedExecutionHandler(
            (r, e) -> schedulingLogger.error(
                    "Execution of task {} was rejected for unknown reasons.", r
            )
    );
    return scheduler;
}
 
開發者ID:chaokunyang,項目名稱:amanda,代碼行數:20,代碼來源:RootContextConfiguration.java

示例2: taskScheduler

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //導入方法依賴的package包/類
@Bean
public ThreadPoolTaskScheduler taskScheduler() {
	String levelString = context.getInitParameter("threadNumber");
	if (levelString == null) {
		levelString = "4";
	}
	int level = Integer.parseInt(levelString);
	log.info("Creating thread pool with " + level + " threads");
	ThreadPoolTaskScheduler exec = new ThreadPoolTaskScheduler();
	exec.setPoolSize(level);
	exec.setThreadNamePrefix("transaction");
	exec.setAwaitTerminationSeconds(60);
	exec.setWaitForTasksToCompleteOnShutdown(true);
	exec.setRejectedExecutionHandler(new RejectedExecutionHandler() {

		@Override
		public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
			StringBuilder errorBuilder = new StringBuilder("Task Rejected");
			log.error(errorBuilder.toString());
		}
	});
	return exec;
}
 
開發者ID:shilongdai,項目名稱:bookManager,代碼行數:24,代碼來源:RootApplicationContextConfig.java

示例3: taskScheduler

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //導入方法依賴的package包/類
@Bean()
public ThreadPoolTaskScheduler taskScheduler() {
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.setPoolSize(100);
scheduler.setThreadNamePrefix("Scheduler-");
scheduler.setWaitForTasksToCompleteOnShutdown(true);
scheduler.setRemoveOnCancelPolicy(true);
   return scheduler;
}
 
開發者ID:PacktPublishing,項目名稱:Spring-5.0-Cookbook,代碼行數:10,代碼來源:SpringScheduledConfig.java

示例4: taskScheduler

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //導入方法依賴的package包/類
@Bean(destroyMethod = "shutdown")
public ThreadPoolTaskScheduler taskScheduler() {
    ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
    scheduler.setPoolSize(20);
    scheduler.setThreadNamePrefix("task-");
    scheduler.setAwaitTerminationSeconds(60);
    scheduler.setWaitForTasksToCompleteOnShutdown(true);
    return scheduler;
}
 
開發者ID:junbaor,項目名稱:telegram-bot,代碼行數:10,代碼來源:AppConfig.java

示例5: taskScheduler

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //導入方法依賴的package包/類
@Bean(destroyMethod = "shutdown")
public Executor taskScheduler() {
    ThreadPoolTaskScheduler threadPool = new ThreadPoolTaskScheduler();
    threadPool.setPoolSize(5);

    // shutdown 時に Task の完了を待つ(最大10分間)
    threadPool.setWaitForTasksToCompleteOnShutdown(true);
    threadPool.setAwaitTerminationSeconds(60 * 10);
    return threadPool;
}
 
開發者ID:sinsengumi,項目名稱:spring-boot-application-infrastructure,代碼行數:11,代碼來源:Application.java

示例6: commonTaskScheduler

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //導入方法依賴的package包/類
@Bean
public ThreadPoolTaskScheduler commonTaskScheduler() {
    final ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
    scheduler.setPoolSize(20);
    scheduler.setWaitForTasksToCompleteOnShutdown(true);
    scheduler.setAwaitTerminationSeconds(30);

    return scheduler;
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-web,代碼行數:10,代碼來源:ExecutorConfig.java

示例7: taskScheduler

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //導入方法依賴的package包/類
@Bean
public ThreadPoolTaskScheduler taskScheduler() {
	int level = 2;
	log.info("Creating thread pool with " + level + " threads");
	ThreadPoolTaskScheduler exec = new ThreadPoolTaskScheduler();
	exec.setPoolSize(level);
	exec.setThreadNamePrefix("transaction");
	exec.setAwaitTerminationSeconds(60);
	exec.setWaitForTasksToCompleteOnShutdown(true);
	exec.setRejectedExecutionHandler((Runnable r, ThreadPoolExecutor executor) -> {
		String errorBuilder = "Task Rejected";
		log.error(errorBuilder);
	});
	return exec;
}
 
開發者ID:shilongdai,項目名稱:LSChatServer,代碼行數:16,代碼來源:ApplicationRootContext.java

示例8: sqlTaskScheduler

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //導入方法依賴的package包/類
@Bean
public TaskScheduler sqlTaskScheduler() {
	ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
	taskScheduler.setWaitForTasksToCompleteOnShutdown(true);
	taskScheduler.setAwaitTerminationSeconds(properties.getBatchTimeout());
	return taskScheduler;
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-stream-app-starters,代碼行數:8,代碼來源:GpfdistSinkConfiguration.java

示例9: setDeadlockGuard

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //導入方法依賴的package包/類
public void setDeadlockGuard(RTMPConnection conn) {
	ThreadPoolTaskScheduler deadlockGuard = new ThreadPoolTaskScheduler();
	deadlockGuard.setPoolSize(16);
	deadlockGuard.setDaemon(false);
	deadlockGuard.setWaitForTasksToCompleteOnShutdown(true);
	deadlockGuard.setThreadNamePrefix("DeadlockGuardScheduler-");
	deadlockGuard.afterPropertiesSet();
	conn.setDeadlockGuardScheduler(deadlockGuard);
}
 
開發者ID:apache,項目名稱:openmeetings,代碼行數:10,代碼來源:Core.java

示例10: taskScheduler

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //導入方法依賴的package包/類
@Bean(name = "taskScheduler")
public ThreadPoolTaskScheduler taskScheduler() {
    ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
    scheduler.setPoolSize(5);
    scheduler.setWaitForTasksToCompleteOnShutdown(false);

    return scheduler;
}
 
開發者ID:bjornharvold,項目名稱:bearchoke,代碼行數:9,代碼來源:SchedulerConfig.java

示例11: onDestroy

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //導入方法依賴的package包/類
@Override
protected void onDestroy() {
    try {
        if (getServletContext().getAttribute("ThreadPoolTaskScheduler") != null) {
            ThreadPoolTaskScheduler executor = (ThreadPoolTaskScheduler) getServletContext()
                    .getAttribute("ThreadPoolTaskScheduler");
            executor.setWaitForTasksToCompleteOnShutdown(false);
            executor.destroy();
        }

        if (getScheduledTaskRegistrar() != null) {
            getScheduledTaskRegistrar().destroy();
        }
        ((BasicDataSource) getBean(DataSource.class)).close();

        EntityManagerFactory entityManagerFactory = getBean(EntityManagerFactory.class);
        if (entityManagerFactory != null) {
            entityManagerFactory.close();
        }

        Enumeration<Driver> drivers = DriverManager.getDrivers();
        Driver d = null;
        while (drivers.hasMoreElements()) {
            try {
                d = drivers.nextElement();
                DriverManager.deregisterDriver(d);
                LOGGER.info("Driver {} deregistered", d);
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
        }

        try {
            Class<?> cls = Class
                    .forName("com.mysql.jdbc.AbandonedConnectionCleanupThread");
            Method mth = (cls == null ? null : cls.getMethod("shutdown"));
            if (mth != null) {
                LOGGER.info("MySQL connection cleanup thread shutdown");
                mth.invoke(null);
                LOGGER.info("MySQL connection cleanup thread shutdown successful");
            }
        } catch (Throwable thr) {
            thr.printStackTrace();
        }

        doDestroy();
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
 
開發者ID:PkayJava,項目名稱:pluggable,代碼行數:51,代碼來源:AbstractWebApplication.java


注:本文中的org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler.setWaitForTasksToCompleteOnShutdown方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。