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