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


Java ThreadPoolTaskScheduler類代碼示例

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


ThreadPoolTaskScheduler類屬於org.springframework.scheduling.concurrent包,在下文中一共展示了ThreadPoolTaskScheduler類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: messageListenerContainer

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //導入依賴的package包/類
@Bean
public MessageListenerContainer messageListenerContainer(
        ConsumerFactory<String, DefaultAvMessage> consumerFactory,
        MessageListener<String, AvMessage> messageListener,
        ThreadPoolTaskScheduler kafkaClientThreadPoolTaskScheduler
) {
    ContainerProperties props = new ContainerProperties(resultTopic);
    // shouldn't be necessary but the default scheduler is not destroyed after shutdown
    props.setScheduler(kafkaClientThreadPoolTaskScheduler);

    MessageListenerContainer container = new ConcurrentMessageListenerContainer<>(
            consumerFactory,
            props
    );
    container.setupMessageListener(messageListener);

    return container;
}
 
開發者ID:dvoraka,項目名稱:av-service,代碼行數:19,代碼來源:KafkaFileClientConfig.java

示例3: postProcessAfterInitialization

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //導入依賴的package包/類
@Test
public void postProcessAfterInitialization() throws Exception {
    assertThat(processor.postProcessAfterInitialization(mock(Executor.class), toBeExcluded).getClass(),
            not(equalTo(ContextAwareExecutor.class)));
    //concurrent
    assertThat(processor.postProcessAfterInitialization(mock(Executor.class), beanName).getClass(),
            equalTo(ContextAwareExecutor.class));
    assertThat(processor.postProcessAfterInitialization(mock(ExecutorService.class), beanName).getClass(),
            equalTo(ContextAwareExecutorService.class));
    assertThat(processor.postProcessAfterInitialization(mock(ScheduledExecutorService.class), beanName).getClass(),
            equalTo(ContextAwareScheduledExecutorService.class));

    //spring
    assertThat(processor.postProcessAfterInitialization(mock(TaskScheduler.class), beanName).getClass(),
            equalTo(ContextAwareTaskScheduler.class));
    assertThat(processor.postProcessAfterInitialization(new ThreadPoolTaskExecutor(), beanName).getClass(),
            equalTo(ContextAwareThreadPoolTaskExecutor.class));
    assertThat(processor.postProcessAfterInitialization(new ThreadPoolTaskScheduler(), beanName).getClass(),
            equalTo(ContextAwareThreadPoolTaskScheduler.class));
    assertThat(processor.postProcessAfterInitialization(mock(AsyncListenableTaskExecutor.class), beanName).getClass(),
            equalTo(ContextAwareAsyncListenableTaskExecutor.class));
    assertThat(processor.postProcessAfterInitialization(mock(AsyncTaskExecutor.class), beanName).getClass(),
            equalTo(ContextAwareAsyncTaskExecutor.class));
    assertThat(processor.postProcessAfterInitialization(mock(SchedulingTaskExecutor.class), beanName).getClass(),
            equalTo(ContextAwareSchedulingTaskExecutor.class));
}
 
開發者ID:enadim,項目名稱:spring-cloud-ribbon-extensions,代碼行數:27,代碼來源:PreservesExecutionContextExecutorStrategyTest.java

示例4: bbTaskScheduler

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //導入依賴的package包/類
@Bean
public TaskScheduler bbTaskScheduler() {
	ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
	taskScheduler.setThreadNamePrefix("API-Schd-ThrP-");
	taskScheduler.setAwaitTerminationSeconds(1);
	taskScheduler.setRejectedExecutionHandler(new ThreadPoolTaskRejectedHandler());
	
	return taskScheduler;
}
 
開發者ID:BuaBook,項目名稱:buabook-api-interface,代碼行數:10,代碼來源:BuaBookApiInterfaceConfig.java

示例5: afterPropertiesSet

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //導入依賴的package包/類
public void afterPropertiesSet() {
    if (properties != null) {
        for (Map.Entry<Object, Object> entry : properties.entrySet()) {
            String key = (String) entry.getKey();
            String value = (String) entry.getValue();

            if ("scheduler.enabled".equals(key)) {
                continue;
            }

            if (key.startsWith(prefix)) {
                String name = key.substring(prefix.length());
                skipMap.put(name, Boolean.valueOf(value));
                logger.info("{} : {}", name, skipMap.get(name));
            }
        }
    }

    if (enabled) {
        instance = new ThreadPoolTaskScheduler();
        instance.afterPropertiesSet();
    }
}
 
開發者ID:zhaojunfei,項目名稱:lemon,代碼行數:24,代碼來源:ProxyTaskScheduler.java

示例6: stompClient

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //導入依賴的package包/類
@Bean
@ConditionalOnMissingBean(WebSocketStompClient.class)
public WebSocketStompClient stompClient(MessageConverter messageConverter,
                                        ThreadPoolTaskScheduler taskScheduler) {
    int bufferSizeLimit = 1024 * 1024 * 8;

    StandardWebSocketClient webSocketClient = new StandardWebSocketClient();
    List<Transport> transports = new ArrayList<>();
    transports.add(new WebSocketTransport(webSocketClient));
    SockJsClient sockJsClient = new SockJsClient(transports);
    WebSocketStompClient client = new WebSocketStompClient(sockJsClient);
    client.setInboundMessageSizeLimit(bufferSizeLimit);
    client.setMessageConverter(messageConverter);
    client.setTaskScheduler(taskScheduler);
    client.setDefaultHeartbeat(new long[]{0, 0});
    return client;
}
 
開發者ID:mthizo247,項目名稱:spring-cloud-netflix-zuul-websocket,代碼行數:18,代碼來源:ZuulWebSocketConfiguration.java

示例7: RedisTestBinder

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //導入依賴的package包/類
public RedisTestBinder(RedisConnectionFactory connectionFactory) {
	RedisMessageChannelBinder binder = new RedisMessageChannelBinder(connectionFactory);
	GenericApplicationContext context = new GenericApplicationContext();
	context.getBeanFactory().registerSingleton(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME,
			new DefaultMessageBuilderFactory());
	DefaultHeaderChannelRegistry channelRegistry = new DefaultHeaderChannelRegistry();
	channelRegistry.setReaperDelay(Long.MAX_VALUE);
	ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
	taskScheduler.afterPropertiesSet();
	channelRegistry.setTaskScheduler(taskScheduler);
	context.getBeanFactory().registerSingleton(
			IntegrationContextUtils.INTEGRATION_HEADER_CHANNEL_REGISTRY_BEAN_NAME,
			channelRegistry);
	context.refresh();
	binder.setApplicationContext(context);
	binder.setCodec(new PojoCodec());
	setBinder(binder);
	template = new StringRedisTemplate(connectionFactory);
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-stream-binder-redis,代碼行數:20,代碼來源:RedisTestBinder.java

示例8: 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

示例9: vaultTaskScheduler

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //導入依賴的package包/類
/**
 * Creates a new {@link TaskSchedulerWrapper} that encapsulates a bean implementing
 * {@link TaskScheduler} and {@link AsyncTaskExecutor}.
 *
 * @return
 * @see ThreadPoolTaskScheduler
 */
@Bean
@Lazy
@ConditionalOnMissingBean(TaskSchedulerWrapper.class)
public TaskSchedulerWrapper vaultTaskScheduler() {

	ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
	threadPoolTaskScheduler.setPoolSize(2);
	threadPoolTaskScheduler.setDaemon(true);
	threadPoolTaskScheduler.setThreadNamePrefix("Spring-Cloud-Vault-");

	// This is to destroy bootstrap resources
	// otherwise, the bootstrap context is not shut down cleanly
	applicationContext.registerShutdownHook();

	return new TaskSchedulerWrapper(threadPoolTaskScheduler);
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-vault,代碼行數:24,代碼來源:VaultBootstrapConfiguration.java

示例10: fileServerMessageListenerContainer

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //導入依賴的package包/類
@Bean
public MessageListenerContainer fileServerMessageListenerContainer(
        ConsumerFactory<String, DefaultAvMessage> consumerFactory,
        MessageListener<String, AvMessage> fileServerMessageListener,
        ThreadPoolTaskScheduler kafkaServerThreadPoolTaskScheduler
) {
    ContainerProperties props = new ContainerProperties(fileTopic);
    // shouldn't be necessary but the default scheduler is not destroyed after shutdown
    props.setScheduler(kafkaServerThreadPoolTaskScheduler);

    MessageListenerContainer container = new ConcurrentMessageListenerContainer<>(
            consumerFactory,
            props
    );
    container.setupMessageListener(fileServerMessageListener);

    return container;
}
 
開發者ID:dvoraka,項目名稱:av-service,代碼行數:19,代碼來源:KafkaServerConfig.java

示例11: init

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //導入依賴的package包/類
@PostConstruct
public void init() {
  this.actionMonitor = new ActionMonitor();
  this.detectionTasks = new HashMap<>();
  this.taskScheduler = new ThreadPoolTaskScheduler();
  this.taskScheduler.setPoolSize(10);
  this.taskScheduler.setWaitForTasksToCompleteOnShutdown(true);
  this.taskScheduler.setRemoveOnCancelPolicy(true);
  this.taskScheduler.setErrorHandler(
      new ErrorHandler() {
        protected Logger log = LoggerFactory.getLogger(this.getClass());

        @Override
        public void handleError(Throwable t) {
          log.error(t.getMessage(), t);
        }
      });
  this.taskScheduler.initialize();
}
 
開發者ID:openbaton,項目名稱:autoscaling-engine,代碼行數:20,代碼來源:DetectionManagement.java

示例12: init

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //導入依賴的package包/類
@PostConstruct
public void init() {
  this.actionMonitor = new ActionMonitor();
  this.executionEngine.setActionMonitor(actionMonitor);
  this.taskScheduler = new ThreadPoolTaskScheduler();
  this.taskScheduler.setPoolSize(10);
  this.taskScheduler.setWaitForTasksToCompleteOnShutdown(true);
  this.taskScheduler.setRemoveOnCancelPolicy(true);
  this.taskScheduler.setErrorHandler(
      new ErrorHandler() {
        protected Logger log = LoggerFactory.getLogger(this.getClass());

        @Override
        public void handleError(Throwable t) {
          log.error(t.getMessage(), t);
        }
      });
  this.taskScheduler.initialize();
}
 
開發者ID:openbaton,項目名稱:autoscaling-engine,代碼行數:20,代碼來源:ExecutionManagement.java

示例13: init

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //導入依賴的package包/類
@PostConstruct
public void init() {
  this.actionMonitor = new ActionMonitor();
  this.taskScheduler = new ThreadPoolTaskScheduler();
  this.taskScheduler.setPoolSize(10);
  this.taskScheduler.setWaitForTasksToCompleteOnShutdown(true);
  this.taskScheduler.setRemoveOnCancelPolicy(true);
  this.taskScheduler.setErrorHandler(
      new ErrorHandler() {
        protected Logger log = LoggerFactory.getLogger(this.getClass());

        @Override
        public void handleError(Throwable t) {
          log.error(t.getMessage(), t);
        }
      });
  this.taskScheduler.initialize();
}
 
開發者ID:openbaton,項目名稱:autoscaling-engine,代碼行數:19,代碼來源:DecisionManagement.java

示例14: afterPropertiesSet

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //導入依賴的package包/類
@Override
public void afterPropertiesSet() {
    final Environment env = beanFactory.getBean(Environment.class);
    TaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
    final String schedulerBeanName = taskScheduler.getClass().getName();
    beanFactory.registerSingleton(schedulerBeanName, taskScheduler);
    beanFactory.initializeBean(taskScheduler, schedulerBeanName);

    final String inMemoryServerAddress = getRatelServiceAddress(env);
    final DiscoveryClient discoveryClient = new DiscoveryClient(inMemoryServerAddress);
    this.ratelServerFetcher = new RatelServerFetcher(discoveryClient);

    this.ratelServerProxyGenerator = new RatelServerProxyGenerator(beanFactory);

    this.ratelServerRegistry = new RatelServerRegistry(new RemoteRestDiscoveryServer(inMemoryServerAddress),
            taskScheduler);
}
 
開發者ID:PayU-Tech,項目名稱:Ratel,代碼行數:18,代碼來源:InMemoryRegistryBeanProviderFactory.java

示例15: initBackgroundJobs

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //導入依賴的package包/類
protected void initBackgroundJobs(WebApplicationContext ctx) {
    try {
        IConfigurationService configurationService = ctx.getBean(IConfigurationService.class);
        IImportExportService importExportService = ctx.getBean(IImportExportService.class);
        IOperationsService operationsService = ctx.getBean(IOperationsService.class);
        
        jobScheduler = new ThreadPoolTaskScheduler();
        jobScheduler.setDaemon(true);
        jobScheduler.setThreadNamePrefix("background-job-");
        jobScheduler.setPoolSize(2);
        jobScheduler.initialize();

        TypedProperties properties = operationsService.findGlobalSetttingsAsProperties();
        if (properties.is(CONFIG_BACKUP_ENABLED, DEFAULT_CONFIG_BACKUP_ENABLED)) {
            jobScheduler.schedule(new BackupJob(importExportService, configurationService, operationsService, getConfigDir(false)),
                    new CronTrigger(
                            properties.get(CONFIG_BACKUP_CRON, DEFAULT_CONFIG_BACKUP_CRON)));
        }
        jobScheduler.scheduleAtFixedRate(() -> configurationService.doInBackground(), 600000);
    } catch (Exception e) {
        LoggerFactory.getLogger(getClass()).info("Failed to schedule  the backup job", e);
    }
}
 
開發者ID:JumpMind,項目名稱:metl,代碼行數:24,代碼來源:AppInitializer.java


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