本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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();
}
}