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


Java TaskExecutor類代碼示例

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


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

示例1: getAsyncExecutor

import org.springframework.core.task.TaskExecutor; //導入依賴的package包/類
@Bean("mvcTaskexecutor")
  public TaskExecutor getAsyncExecutor() {
		ConcurrentTaskExecutor executor = new ConcurrentTaskExecutor(
                 Executors.newFixedThreadPool(100));

		executor.setTaskDecorator(new TaskDecorator() {
           @Override
           public Runnable decorate (Runnable runnable) {
               return () -> {
  
                   long t = System.currentTimeMillis();
                   runnable.run();
                   System.out.printf("Thread %s has a processing time:  %s%n", Thread.currentThread().getName(),       
                                     (System.currentTimeMillis() - t));
               };
           }
       });
		return executor;
}
 
開發者ID:PacktPublishing,項目名稱:Spring-5.0-Cookbook,代碼行數:20,代碼來源:BatchConfig.java

示例2: getWebSocketConsumersManager

import org.springframework.core.task.TaskExecutor; //導入依賴的package包/類
/**
 * Manages kafka consumers running in a background processing thread for websocket consumers.
 * @param webKafkaConsumerFactory Factory for creating new Consumers
 * @param messagingTemplate messaging template instance for passing websocket messages.
 * @param backgroundConsumerExecutor The executor to run our manager in.
 * @param appProperties defined app properties.
 * @return manager instance for web socket consumers.
 */
@Bean
public WebSocketConsumersManager getWebSocketConsumersManager(
    final WebKafkaConsumerFactory webKafkaConsumerFactory,
    final SimpMessagingTemplate messagingTemplate,
    final TaskExecutor backgroundConsumerExecutor,
    final AppProperties appProperties) {

    // Create manager
    final WebSocketConsumersManager manager = new WebSocketConsumersManager(
        webKafkaConsumerFactory,
        messagingTemplate,
        appProperties.getMaxConcurrentWebSocketConsumers()
    );

    // Submit to executor service
    backgroundConsumerExecutor.execute(manager);

    return manager;
}
 
開發者ID:SourceLabOrg,項目名稱:kafka-webview,代碼行數:28,代碼來源:WebSocketConfig.java

示例3: createDefaultTaskExecutor

import org.springframework.core.task.TaskExecutor; //導入依賴的package包/類
private TaskExecutor createDefaultTaskExecutor() {
	// create thread-pool for starting contexts
	ThreadGroup threadGroup =
			new ThreadGroup("eclipse-gemini-blueprint-extender[" + ObjectUtils.getIdentityHexString(this) + "]-threads");
	threadGroup.setDaemon(false);

	ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
	taskExecutor.setMaxPoolSize(Runtime.getRuntime().availableProcessors());
	taskExecutor.setThreadGroup(threadGroup);
	taskExecutor.setThreadNamePrefix("EclipseGeminiBlueprintExtenderThread-");
	taskExecutor.initialize();

	isTaskExecutorManagedInternally = true;

	return taskExecutor;
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:17,代碼來源:ExtenderConfiguration.java

示例4: afterPropertiesSet

import org.springframework.core.task.TaskExecutor; //導入依賴的package包/類
@Override
public void afterPropertiesSet() throws Exception {
	BeanWrapper bw = new BeanWrapperImpl(ThreadPoolTaskExecutor.class);
	determinePoolSizeRange(bw);
	if (this.queueCapacity != null) {
		bw.setPropertyValue("queueCapacity", this.queueCapacity);
	}
	if (this.keepAliveSeconds != null) {
		bw.setPropertyValue("keepAliveSeconds", this.keepAliveSeconds);
	}
	if (this.rejectedExecutionHandler != null) {
		bw.setPropertyValue("rejectedExecutionHandler", this.rejectedExecutionHandler);
	}
	if (this.beanName != null) {
		bw.setPropertyValue("threadNamePrefix", this.beanName + "-");
	}
	this.target = (TaskExecutor) bw.getWrappedInstance();
	if (this.target instanceof InitializingBean) {
		((InitializingBean) this.target).afterPropertiesSet();
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:22,代碼來源:TaskExecutorFactoryBean.java

示例5: requestAsync

import org.springframework.core.task.TaskExecutor; //導入依賴的package包/類
public static <T> DeferredResult<T> requestAsync(final TaskExecutor executor,
    final Callable<T> action) {
    final DeferredResult<T> result = new DeferredResult<>();

    final Runnable beforeCallable = () -> {
        try {
            T t = action.call();

            if (result.isSetOrExpired()) {
                log.error("async request expired");
                return;
            }

            result.setResult(t);
        } catch (final Exception ex) {
            result.setErrorResult(ex);
        }
    };

    executor.execute(beforeCallable);
    return result;
}
 
開發者ID:rsdomingues,項目名稱:wiredtigervsvmap,代碼行數:23,代碼來源:DeferredResultAdapter.java

示例6: getTeamProcessorThreadPool

import org.springframework.core.task.TaskExecutor; //導入依賴的package包/類
@Bean(name = "teamProcessorThreadPool")
public TaskExecutor getTeamProcessorThreadPool(Environment applicationProperties) {
  ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();

  taskExecutor.setAllowCoreThreadTimeOut(false);

  taskExecutor
      .setCorePoolSize(
          Integer.valueOf(applicationProperties.getProperty("teams.threads.size.core")));
  taskExecutor.setMaxPoolSize(
      Integer.valueOf(applicationProperties.getProperty("teams.threads.size.maxpool")));
  taskExecutor.setQueueCapacity(
      Integer.valueOf(applicationProperties.getProperty("teams.threads.queue.capacity")));
  taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
  taskExecutor.setKeepAliveSeconds(5);
  taskExecutor.setWaitForTasksToCompleteOnShutdown(true);
  taskExecutor.setThreadNamePrefix("teamTP-");

  return taskExecutor;
}
 
開發者ID:dentinger,項目名稱:LeagueManager,代碼行數:21,代碼來源:ThreadPoolConfig.java

示例7: getLeagueProcessorThreadPool

import org.springframework.core.task.TaskExecutor; //導入依賴的package包/類
@Bean(name = "leagueProcessorThreadPool")
public TaskExecutor getLeagueProcessorThreadPool(Environment applicationProperties) {
  ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();

  taskExecutor.setAllowCoreThreadTimeOut(false);

  taskExecutor
      .setCorePoolSize(
          Integer.valueOf(applicationProperties.getProperty("leagues.threads.size.core")));
  taskExecutor.setMaxPoolSize(
      Integer.valueOf(applicationProperties.getProperty("leagues.threads.size.maxpool")));
  taskExecutor.setQueueCapacity(
      Integer.valueOf(applicationProperties.getProperty("leagues.threads.queue.capacity")));
  taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
  taskExecutor.setKeepAliveSeconds(5);
  taskExecutor.setWaitForTasksToCompleteOnShutdown(true);
  taskExecutor.setThreadNamePrefix("leagueTP-");

  return taskExecutor;
}
 
開發者ID:dentinger,項目名稱:LeagueManager,代碼行數:21,代碼來源:ThreadPoolConfig.java

示例8: getPersonProcessorThreadPool

import org.springframework.core.task.TaskExecutor; //導入依賴的package包/類
@Bean(name = "personProcessorThreadPool")
public TaskExecutor getPersonProcessorThreadPool(Environment applicationProperties) {
  ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();

  taskExecutor.setAllowCoreThreadTimeOut(false);

  taskExecutor
      .setCorePoolSize(
          Integer.valueOf(applicationProperties.getProperty("persons.threads.size.core")));
  taskExecutor.setMaxPoolSize(
      Integer.valueOf(applicationProperties.getProperty("persons.threads.size.maxpool")));
  taskExecutor.setQueueCapacity(
      Integer.valueOf(applicationProperties.getProperty("persons.threads.queue.capacity")));
  taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
  taskExecutor.setKeepAliveSeconds(5);
  taskExecutor.setWaitForTasksToCompleteOnShutdown(true);
  taskExecutor.setThreadNamePrefix("personTP-");

  return taskExecutor;
}
 
開發者ID:dentinger,項目名稱:LeagueManager,代碼行數:21,代碼來源:ThreadPoolConfig.java

示例9: ReverseProxyFilter

import org.springframework.core.task.TaskExecutor; //導入依賴的package包/類
public ReverseProxyFilter(
        CharonProperties charon,
        RetryOperations retryOperations,
        RetryOperations defaultRetryOperations,
        RequestDataExtractor extractor,
        MappingsProvider mappingsProvider,
        TaskExecutor taskExecutor,
        RequestForwarder requestForwarder,
        TraceInterceptor traceInterceptor
) {
    this.charon = charon;
    this.retryOperations = retryOperations;
    this.defaultRetryOperations = defaultRetryOperations;
    this.extractor = extractor;
    this.mappingsProvider = mappingsProvider;
    this.taskExecutor = taskExecutor;
    this.requestForwarder = requestForwarder;
    this.traceInterceptor = traceInterceptor;
}
 
開發者ID:mkopylec,項目名稱:charon-spring-boot-starter,代碼行數:20,代碼來源:ReverseProxyFilter.java

示例10: MFEventBus

import org.springframework.core.task.TaskExecutor; //導入依賴的package包/類
@Autowired
public MFEventBus(final TaskExecutor taskExecutor)
{
	super();

	eventBus = new AsyncEventBus(taskExecutor, new SubscriberExceptionHandler()
	{

		@Override
		public void handleException(final Throwable exception, final SubscriberExceptionContext context)
		{
			onEventBusException(exception, context);

		}
	});

	eventBus.register(this);
}
 
開發者ID:metasfresh,項目名稱:metasfresh-procurement-webui,代碼行數:19,代碼來源:MFEventBus.java

示例11: camundaTaskExecutor

import org.springframework.core.task.TaskExecutor; //導入依賴的package包/類
@Bean(name = CAMUNDA_TASK_EXECUTOR_QUALIFIER)
@ConditionalOnMissingBean(name = CAMUNDA_TASK_EXECUTOR_QUALIFIER)
@ConditionalOnProperty(prefix = "camunda.bpm.job-execution", name = "enabled", havingValue = "true", matchIfMissing = true)
public static TaskExecutor camundaTaskExecutor(CamundaBpmProperties properties) {
  int corePoolSize = properties.getJobExecution().getCorePoolSize();
  int maxPoolSize = properties.getJobExecution().getMaxPoolSize();

  final ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();

  threadPoolTaskExecutor.setCorePoolSize(corePoolSize);
  threadPoolTaskExecutor.setMaxPoolSize(maxPoolSize);


  LOG.configureJobExecutorPool(corePoolSize, maxPoolSize);
  return threadPoolTaskExecutor;
}
 
開發者ID:camunda,項目名稱:camunda-bpm-spring-boot-starter,代碼行數:17,代碼來源:DefaultJobConfiguration.java

示例12: testActivitiThreadPoolUsesConfiguredValues

import org.springframework.core.task.TaskExecutor; //導入依賴的package包/類
/**
 * Ensure that the Activiti's thread pool uses the correct configuration value.
 * 
 * This assertion is limited in that the configuration values must be set before Spring application context is initialized, which we cannot control easily
 * in unit test.
 */
@Test
public void testActivitiThreadPoolUsesConfiguredValues()
{
    AsyncExecutor asyncExecutor = processEngineConfiguration.getAsyncExecutor();
    SpringAsyncExecutor springAsyncExecutor = (SpringAsyncExecutor) asyncExecutor;
    TaskExecutor taskExecutor = springAsyncExecutor.getTaskExecutor();
    ThreadPoolTaskExecutor threadPoolTaskExecutor = (ThreadPoolTaskExecutor) taskExecutor;

    Integer corePoolSize = threadPoolTaskExecutor.getCorePoolSize();
    Integer maxPoolSize = threadPoolTaskExecutor.getMaxPoolSize();
    Integer keepAliveSeconds = threadPoolTaskExecutor.getKeepAliveSeconds();
    // No real easy way of getting the queue capacity from the already constructed thread pool
    Integer remainingCapacity = ((LinkedBlockingQueue<?>) threadPoolTaskExecutor.getThreadPoolExecutor().getQueue()).remainingCapacity();

    assertEquals(configurationHelper.getProperty(ConfigurationValue.ACTIVITI_THREAD_POOL_CORE_POOL_SIZE, Integer.class), corePoolSize);
    assertEquals(configurationHelper.getProperty(ConfigurationValue.ACTIVITI_THREAD_POOL_MAX_POOL_SIZE, Integer.class), maxPoolSize);
    assertEquals(configurationHelper.getProperty(ConfigurationValue.ACTIVITI_THREAD_POOL_KEEP_ALIVE_SECS, Integer.class), keepAliveSeconds);
    assertEquals(configurationHelper.getProperty(ConfigurationValue.ACTIVITI_THREAD_POOL_QUEUE_CAPACITY, Integer.class), remainingCapacity);
}
 
開發者ID:FINRAOS,項目名稱:herd,代碼行數:26,代碼來源:ActivitiProcessEngineConfigurationTest.java

示例13: LCServiceInstanceService

import org.springframework.core.task.TaskExecutor; //導入依賴的package包/類
@Autowired
public LCServiceInstanceService(
		final CopyProvider copyProvider,
		final DataProvider dataProvider,
		@Value("#{environment.SOURCE_INSTANCE_ID}") final String sourceInstanceId,
		final BrokerActionRepository brokerRepo,
		final LCServiceInstanceManager instanceManager,
		final TaskExecutor executor,
		final DataProviderService dataProviderService) {
	this.copyProvider = copyProvider;
	this.dataProvider = dataProvider;
	this.sourceInstanceId = sourceInstanceId;
	this.brokerRepo = brokerRepo;
	this.instanceManager = instanceManager;
	this.executor = executor;
	this.dataProviderService = dataProviderService;
}
 
開發者ID:krujos,項目名稱:data-lifecycle-service-broker,代碼行數:18,代碼來源:LCServiceInstanceService.java

示例14: taskExecutor

import org.springframework.core.task.TaskExecutor; //導入依賴的package包/類
@Bean
    public TaskExecutor taskExecutor() {
        //https://jira.spring.io/browse/BATCH-2269
        final SimpleAsyncTaskExecutor simpleAsyncTaskExecutor = new SimpleAsyncTaskExecutor() {
            @Override
            protected void doExecute(Runnable task) {
                //gets the jobExecution of the configuration thread
                final JobExecution jobExecution = JobSynchronizationManager.getContext().getJobExecution();
                super.doExecute(() -> {
                    JobSynchronizationManager.register(jobExecution);
                    try {
                        task.run();
                    } finally {
//                        JobSynchronizationManager.release();
                        JobSynchronizationManager.close();
                    }
                });
            }
        };
        simpleAsyncTaskExecutor.setConcurrencyLimit(20);
        return simpleAsyncTaskExecutor;
    }
 
開發者ID:commercetools,項目名稱:commercetools-sunrise-data,代碼行數:23,代碼來源:SuggestKeywordsFromNameJobConfiguration.java

示例15: launchImmediately

import org.springframework.core.task.TaskExecutor; //導入依賴的package包/類
private JobExecution launchImmediately(TaskExecutor taskExecutor, Job job, JobParameters jobParameters)
{
	try
	{
		SimpleJobLauncher launcher = new SimpleJobLauncher();
		launcher.setJobRepository(jobRepository);
		launcher.setTaskExecutor(taskExecutor);
		return launcher.run(job, jobParameters);
	}
	catch (JobExecutionAlreadyRunningException | JobRestartException | JobInstanceAlreadyCompleteException
			| JobParametersInvalidException e)
	{
		logger.error("Unexpected exception", e);
		throw YonaException.unexpected(e);
	}
}
 
開發者ID:yonadev,項目名稱:yona-server,代碼行數:17,代碼來源:BatchTaskService.java


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