本文整理汇总了Java中org.springframework.scheduling.concurrent.ConcurrentTaskExecutor类的典型用法代码示例。如果您正苦于以下问题:Java ConcurrentTaskExecutor类的具体用法?Java ConcurrentTaskExecutor怎么用?Java ConcurrentTaskExecutor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConcurrentTaskExecutor类属于org.springframework.scheduling.concurrent包,在下文中一共展示了ConcurrentTaskExecutor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAsyncExecutor
import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor; //导入依赖的package包/类
@Bean("mvcTaskexecutor")
@Override
public Executor 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: getAsyncExecutor
import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor; //导入依赖的package包/类
@Bean("mvcTaskexecutor")
@Override
public Executor 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();
logger.info("creating ConcurrentTaskExecutor thread pool....");
System.out.printf("Thread %s has a processing time: %s%n", Thread.currentThread().getName(),
(System.currentTimeMillis() - t));
};
}
});
return executor;
}
示例3: getAsyncExecutor
import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor; //导入依赖的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;
}
示例4: testAsyncSupportOptions
import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor; //导入依赖的package包/类
@Test
public void testAsyncSupportOptions() throws Exception {
loadBeanDefinitions("mvc-config-async-support.xml", 15);
RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
assertNotNull(adapter);
DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(adapter);
assertEquals(ConcurrentTaskExecutor.class, fieldAccessor.getPropertyValue("taskExecutor").getClass());
assertEquals(2500L, fieldAccessor.getPropertyValue("asyncRequestTimeout"));
CallableProcessingInterceptor[] callableInterceptors =
(CallableProcessingInterceptor[]) fieldAccessor.getPropertyValue("callableInterceptors");
assertEquals(1, callableInterceptors.length);
DeferredResultProcessingInterceptor[] deferredResultInterceptors =
(DeferredResultProcessingInterceptor[]) fieldAccessor.getPropertyValue("deferredResultInterceptors");
assertEquals(1, deferredResultInterceptors.length);
}
示例5: registerAsyncClientHttpRequestFactory
import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor; //导入依赖的package包/类
private String registerAsyncClientHttpRequestFactory(final String id, final Client client) {
return registry.registerIfAbsent(id, AsyncClientHttpRequestFactory.class, () -> {
log.debug("Client [{}]: Registering RestAsyncClientHttpRequestFactory", id);
final BeanDefinitionBuilder factory =
genericBeanDefinition(RestAsyncClientHttpRequestFactory.class);
factory.addConstructorArgReference(registerHttpClient(id, client));
factory.addConstructorArgValue(genericBeanDefinition(ConcurrentTaskExecutor.class)
// we allow users to use their own ExecutorService, but they don't have to configure tracing
.addConstructorArgValue(registerExecutor(id, client))
.getBeanDefinition());
return factory;
});
}
示例6: testAsyncSupportOptions
import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor; //导入依赖的package包/类
@Test
public void testAsyncSupportOptions() throws Exception {
loadBeanDefinitions("mvc-config-async-support.xml", 13);
RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
assertNotNull(adapter);
DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(adapter);
assertEquals(ConcurrentTaskExecutor.class, fieldAccessor.getPropertyValue("taskExecutor").getClass());
assertEquals(2500L, fieldAccessor.getPropertyValue("asyncRequestTimeout"));
CallableProcessingInterceptor[] callableInterceptors =
(CallableProcessingInterceptor[]) fieldAccessor.getPropertyValue("callableInterceptors");
assertEquals(1, callableInterceptors.length);
DeferredResultProcessingInterceptor[] deferredResultInterceptors =
(DeferredResultProcessingInterceptor[]) fieldAccessor.getPropertyValue("deferredResultInterceptors");
assertEquals(1, deferredResultInterceptors.length);
}
示例7: registerAsyncListenableTaskExecutor
import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor; //导入依赖的package包/类
private String registerAsyncListenableTaskExecutor(final String id) {
return registry.register(id, AsyncListenableTaskExecutor.class, () -> {
LOG.debug("Client [{}]: Registering AsyncListenableTaskExecutor", id);
return genericBeanDefinition(ConcurrentTaskExecutor.class)
.addConstructorArgValue(BeanDefinitionBuilder.genericBeanDefinition(TracingExecutors.class)
.setFactoryMethod("preserve")
.addConstructorArgValue(genericBeanDefinition(Executors.class)
.setFactoryMethod("newCachedThreadPool")
.setDestroyMethodName("shutdown")
.getBeanDefinition())
.addConstructorArgReference("tracer")
.getBeanDefinition());
});
}
示例8: sqsPollerExecutor
import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor; //导入依赖的package包/类
@Bean
public AsyncTaskExecutor sqsPollerExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(SQS_POLLER_THREAD_POOL_SIZE);
executor.setThreadNamePrefix(SQS_POLLER_THREAD_NAME_PREFIX);
executor.setWaitForTasksToCompleteOnShutdown(false);
executor.initialize();
return new ConcurrentTaskExecutor(executor);
}
示例9: simpleRequestFactory
import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor; //导入依赖的package包/类
static HttpConfigurer simpleRequestFactory(final ExecutorService executor) {
return builder -> {
final SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
factory.setTaskExecutor(new ConcurrentTaskExecutor(executor));
builder.requestFactory(factory);
};
}
示例10: exampleAsyncClientHttpRequestFactory
import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor; //导入依赖的package包/类
@Bean
public RestAsyncClientHttpRequestFactory exampleAsyncClientHttpRequestFactory(
final AccessTokens tokens, final Tracer tracer, final Logbook logbook,
final ExecutorService executor) throws Exception {
return new RestAsyncClientHttpRequestFactory(
HttpClientBuilder.create()
.setDefaultRequestConfig(RequestConfig.custom()
.setConnectTimeout(5000)
.setSocketTimeout(5000)
.build())
.setConnectionTimeToLive(30, SECONDS)
.setMaxConnPerRoute(2)
.setMaxConnTotal(20)
.addInterceptorFirst(new AccessTokensRequestInterceptor("example", tokens))
.addInterceptorFirst(new TracerHttpRequestInterceptor(tracer))
.addInterceptorLast(new LogbookHttpRequestInterceptor(logbook))
.addInterceptorLast(new GzippingHttpRequestInterceptor())
.addInterceptorLast(new LogbookHttpResponseInterceptor())
.setSSLSocketFactory(new SSLConnectionSocketFactory(
SSLContexts.custom()
.loadTrustMaterial(
getClass().getClassLoader().getResource("example.keystore"),
"password".toCharArray())
.build(),
getDefaultHostnameVerifier()))
.build(),
new ConcurrentTaskExecutor(executor));
}
示例11: requestMappingHandlerAdapter
import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void requestMappingHandlerAdapter() throws Exception {
RequestMappingHandlerAdapter adapter = webConfig.requestMappingHandlerAdapter();
// ConversionService
String actual = webConfig.mvcConversionService().convert(new TestBean(), String.class);
assertEquals("converted", actual);
// Message converters
assertEquals(1, adapter.getMessageConverters().size());
DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(adapter);
// Custom argument resolvers and return value handlers
List<HandlerMethodArgumentResolver> argResolvers =
(List<HandlerMethodArgumentResolver>) fieldAccessor.getPropertyValue("customArgumentResolvers");
assertEquals(1, argResolvers.size());
List<HandlerMethodReturnValueHandler> handlers =
(List<HandlerMethodReturnValueHandler>) fieldAccessor.getPropertyValue("customReturnValueHandlers");
assertEquals(1, handlers.size());
// Async support options
assertEquals(ConcurrentTaskExecutor.class, fieldAccessor.getPropertyValue("taskExecutor").getClass());
assertEquals(2500L, fieldAccessor.getPropertyValue("asyncRequestTimeout"));
CallableProcessingInterceptor[] callableInterceptors =
(CallableProcessingInterceptor[]) fieldAccessor.getPropertyValue("callableInterceptors");
assertEquals(1, callableInterceptors.length);
DeferredResultProcessingInterceptor[] deferredResultInterceptors =
(DeferredResultProcessingInterceptor[]) fieldAccessor.getPropertyValue("deferredResultInterceptors");
assertEquals(1, deferredResultInterceptors.length);
assertEquals(false, fieldAccessor.getPropertyValue("ignoreDefaultModelOnRedirect"));
}
示例12: requestMappingHandlerAdapter
import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void requestMappingHandlerAdapter() throws Exception {
RequestMappingHandlerAdapter adapter = this.config.requestMappingHandlerAdapter();
// ConversionService
String actual = this.config.mvcConversionService().convert(new TestBean(), String.class);
assertEquals("converted", actual);
// Message converters
assertEquals(2, adapter.getMessageConverters().size());
assertEquals(StringHttpMessageConverter.class, adapter.getMessageConverters().get(0).getClass());
assertEquals(MappingJackson2HttpMessageConverter.class, adapter.getMessageConverters().get(1).getClass());
ObjectMapper objectMapper = ((MappingJackson2HttpMessageConverter)adapter.getMessageConverters().get(1)).getObjectMapper();
assertFalse(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
assertFalse(objectMapper.getSerializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
assertFalse(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(adapter);
// Custom argument resolvers and return value handlers
List<HandlerMethodArgumentResolver> argResolvers =
(List<HandlerMethodArgumentResolver>) fieldAccessor.getPropertyValue("customArgumentResolvers");
assertEquals(1, argResolvers.size());
List<HandlerMethodReturnValueHandler> handlers =
(List<HandlerMethodReturnValueHandler>) fieldAccessor.getPropertyValue("customReturnValueHandlers");
assertEquals(1, handlers.size());
// Async support options
assertEquals(ConcurrentTaskExecutor.class, fieldAccessor.getPropertyValue("taskExecutor").getClass());
assertEquals(2500L, fieldAccessor.getPropertyValue("asyncRequestTimeout"));
CallableProcessingInterceptor[] callableInterceptors =
(CallableProcessingInterceptor[]) fieldAccessor.getPropertyValue("callableInterceptors");
assertEquals(1, callableInterceptors.length);
DeferredResultProcessingInterceptor[] deferredResultInterceptors =
(DeferredResultProcessingInterceptor[]) fieldAccessor.getPropertyValue("deferredResultInterceptors");
assertEquals(1, deferredResultInterceptors.length);
assertEquals(false, fieldAccessor.getPropertyValue("ignoreDefaultModelOnRedirect"));
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:44,代码来源:WebMvcConfigurationSupportExtensionTests.java
示例13: configureAsyncSupport
import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor; //导入依赖的package包/类
@Override
public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
configurer.setDefaultTimeout(2500).setTaskExecutor(new ConcurrentTaskExecutor())
.registerCallableInterceptors(new CallableProcessingInterceptorAdapter() { })
.registerDeferredResultInterceptors(new DeferredResultProcessingInterceptorAdapter() {});
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:7,代码来源:WebMvcConfigurationSupportExtensionTests.java
示例14: shouldAutowire
import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor; //导入依赖的package包/类
@Test
public void shouldAutowire() {
assertThat(unit.getClass(), is(ConcurrentTaskExecutor.class));
}
示例15: taskExecutor
import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor; //导入依赖的package包/类
@Primary
@Bean(name = DEFAULT_TASK_EXECUTOR_BEAN_NAME)
@ConditionalOnMissingBean(name = DEFAULT_TASK_EXECUTOR_BEAN_NAME)
public TaskExecutor taskExecutor(final ExecutorService taskExecutorService, final Tracer tracer) {
return new ConcurrentTaskExecutor(tryPreserve(taskExecutorService, tracer));
}