本文整理匯總了Java中org.springframework.core.task.AsyncTaskExecutor類的典型用法代碼示例。如果您正苦於以下問題:Java AsyncTaskExecutor類的具體用法?Java AsyncTaskExecutor怎麽用?Java AsyncTaskExecutor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
AsyncTaskExecutor類屬於org.springframework.core.task包,在下文中一共展示了AsyncTaskExecutor類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: postProcessAfterInitialization
import org.springframework.core.task.AsyncTaskExecutor; //導入依賴的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
示例2: determineAsyncExecutor
import org.springframework.core.task.AsyncTaskExecutor; //導入依賴的package包/類
/**
* Determine the specific executor to use when executing the given method.
* @return the executor to use (or {@code null}, but just if no default executor has been set)
*/
protected AsyncTaskExecutor determineAsyncExecutor(Method method) {
AsyncTaskExecutor executor = this.executors.get(method);
if (executor == null) {
Executor executorToUse = this.defaultExecutor;
String qualifier = getExecutorQualifier(method);
if (StringUtils.hasLength(qualifier)) {
Assert.notNull(this.beanFactory, "BeanFactory must be set on " + getClass().getSimpleName() +
" to access qualified executor '" + qualifier + "'");
executorToUse = BeanFactoryAnnotationUtils.qualifiedBeanOfType(
this.beanFactory, Executor.class, qualifier);
}
else if (executorToUse == null) {
return null;
}
executor = (executorToUse instanceof AsyncTaskExecutor ?
(AsyncTaskExecutor) executorToUse : new TaskExecutorAdapter(executorToUse));
this.executors.put(method, executor);
}
return executor;
}
示例3: determineAsyncExecutor
import org.springframework.core.task.AsyncTaskExecutor; //導入依賴的package包/類
/**
* Determine the specific executor to use when executing the given method.
* Should preferably return an {@link AsyncListenableTaskExecutor} implementation.
* @return the executor to use (or {@code null}, but just if no default executor has been set)
*/
protected AsyncTaskExecutor determineAsyncExecutor(Method method) {
AsyncTaskExecutor executor = this.executors.get(method);
if (executor == null) {
Executor executorToUse = this.defaultExecutor;
String qualifier = getExecutorQualifier(method);
if (StringUtils.hasLength(qualifier)) {
if (this.beanFactory == null) {
throw new IllegalStateException("BeanFactory must be set on " + getClass().getSimpleName() +
" to access qualified executor '" + qualifier + "'");
}
executorToUse = BeanFactoryAnnotationUtils.qualifiedBeanOfType(
this.beanFactory, Executor.class, qualifier);
}
else if (executorToUse == null) {
return null;
}
executor = (executorToUse instanceof AsyncListenableTaskExecutor ?
(AsyncListenableTaskExecutor) executorToUse : new TaskExecutorAdapter(executorToUse));
this.executors.put(method, executor);
}
return executor;
}
示例4: doSubmit
import org.springframework.core.task.AsyncTaskExecutor; //導入依賴的package包/類
/**
* Delegate for actually executing the given task with the chosen executor.
* @param task the task to execute
* @param executor the chosen executor
* @param returnType the declared return type (potentially a {@link Future} variant)
* @return the execution result (potentially a corresponding {@link Future} handle)
*/
protected Object doSubmit(Callable<Object> task, AsyncTaskExecutor executor, Class<?> returnType) {
if (completableFuturePresent) {
Future<Object> result = CompletableFutureDelegate.processCompletableFuture(returnType, task, executor);
if (result != null) {
return result;
}
}
if (ListenableFuture.class.isAssignableFrom(returnType)) {
return ((AsyncListenableTaskExecutor) executor).submitListenable(task);
}
else if (Future.class.isAssignableFrom(returnType)) {
return executor.submit(task);
}
else {
executor.submit(task);
return null;
}
}
示例5: startCallableProcessingWithAsyncTask
import org.springframework.core.task.AsyncTaskExecutor; //導入依賴的package包/類
@Test
public void startCallableProcessingWithAsyncTask() throws Exception {
AsyncTaskExecutor executor = mock(AsyncTaskExecutor.class);
given(this.asyncWebRequest.getNativeRequest(HttpServletRequest.class)).willReturn(this.servletRequest);
@SuppressWarnings("unchecked")
WebAsyncTask<Object> asyncTask = new WebAsyncTask<Object>(1000L, executor, mock(Callable.class));
this.asyncManager.startCallableProcessing(asyncTask);
verify(executor).submit((Runnable) notNull());
verify(this.asyncWebRequest).setTimeout(1000L);
verify(this.asyncWebRequest).addTimeoutHandler(any(Runnable.class));
verify(this.asyncWebRequest).addCompletionHandler(any(Runnable.class));
verify(this.asyncWebRequest).startAsync();
}
示例6: deleteFiles
import org.springframework.core.task.AsyncTaskExecutor; //導入依賴的package包/類
/**
* 根據文件訪問URL列表, 將文件從雲存儲或應用係統Context路徑下的文件刪除
* <p>
* 調用帶有返回值的多線程(實現callable接口),也是同步的。參考:http://blueram.iteye.com/blog/1583117
*
* @param fileUrls
* @return 返回存儲路徑
*/
public Integer deleteFiles(Collection<String> fileUrls) {
int count = 0;
AsyncTaskExecutor executor = new SimpleAsyncTaskExecutor();
for (String url : fileUrls) {
final String fileUrl = StringUtils.substringAfterLast(url, coreConfig.getValue("bae.bcs.bucket") + "/");
try {
Future<Integer> future = executor.submit(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
deleteFile(fileUrl);
return 1;
}
});
count += future.get();
} catch (InterruptedException | ExecutionException e) {
Exceptions.printException(e);
}
}
return count;
}
示例7: asyncExecutor
import org.springframework.core.task.AsyncTaskExecutor; //導入依賴的package包/類
/**
* Crea un nuevo executor. Véase {@link #getAsyncExecutor()}
*
* @return {@link Executor} de tareas asíncronas
* @see <a href="http://appcia.cnc.una.py/wf/index.php/Asyn_task">Wiki</a>
*/
@Bean
public AsyncTaskExecutor asyncExecutor() {
final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(
getInt("karaku.async.pool.size", DEFAULT_CORE_POOL_SIZE));
executor.setMaxPoolSize(getInt("karaku.async.pool.max_size",
DEFAULT_CORE_POOL_MAX_SIZE));
executor.setQueueCapacity(
getInt("karaku.async.queue.size", DEFAULT_ASYNC_QUEUE_SIZE));
executor.setThreadNamePrefix(properties
.get("karaku.async.thread.prefix", DEFAULT_THREAD_PREFIX));
// TODO cambiar por un SyncTaskExecutor
return executor;
}
示例8: createDefaultTaskExecutor
import org.springframework.core.task.AsyncTaskExecutor; //導入依賴的package包/類
/**
* Create a default TaskExecutor. Called if no explicit TaskExecutor has been specified.
* <p>The default implementation builds a {@link org.springframework.core.task.SimpleAsyncTaskExecutor}
* with the specified bean name (or the class name, if no bean name specified) as thread name prefix.
*
* @return a {@link org.springframework.core.task.SimpleAsyncTaskExecutor} configured with the thread name prefix
* @see org.springframework.core.task.SimpleAsyncTaskExecutor#SimpleAsyncTaskExecutor(String)
*/
protected AsyncTaskExecutor createDefaultTaskExecutor() {
String beanName = getBeanName();
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
threadPoolTaskExecutor.setThreadNamePrefix(beanName != null ? beanName + "-" : DEFAULT_THREAD_NAME_PREFIX);
int spinningThreads = this.getRegisteredQueues().size();
if (spinningThreads > 0) {
threadPoolTaskExecutor.setCorePoolSize(spinningThreads * DEFAULT_WORKER_THREADS);
int maxNumberOfMessagePerBatch = getMaxNumberOfMessages() != null ? getMaxNumberOfMessages() : DEFAULT_WORKER_THREADS;
threadPoolTaskExecutor.setMaxPoolSize(spinningThreads * (maxNumberOfMessagePerBatch + 1));
}
// No use of a thread pool executor queue to avoid retaining message to long in memory
threadPoolTaskExecutor.setQueueCapacity(0);
threadPoolTaskExecutor.afterPropertiesSet();
return threadPoolTaskExecutor;
}
示例9: listenForAnswersOf
import org.springframework.core.task.AsyncTaskExecutor; //導入依賴的package包/類
private void listenForAnswersOf(
LifxMessage messageSent,
LifxMessageType expectedResponseType,
CompletableFuture<LifxMessage[]> results) {
this.clientsWaiting.put(expectedResponseType, results);
if (this.listening) return;
this.listening = true;
log.debug("|-- Going to start listen task..");
if(this.listenerExecutor instanceof AsyncTaskExecutor){
((AsyncTaskExecutor)this.listenerExecutor).execute(
new UdpListenExcecutor(clientsWaiting), AsyncTaskExecutor.TIMEOUT_IMMEDIATE );
}else{
this.listenerExecutor.execute(new UdpListenExcecutor(clientsWaiting));
}
}
示例10: WebAsyncTask
import org.springframework.core.task.AsyncTaskExecutor; //導入依賴的package包/類
private WebAsyncTask(Long timeout, AsyncTaskExecutor executor, String executorName, Callable<V> callable) {
Assert.notNull(callable, "Callable must not be null");
this.callable = callable;
this.timeout = timeout;
this.executor = executor;
this.executorName = executorName;
}
示例11: getExecutor
import org.springframework.core.task.AsyncTaskExecutor; //導入依賴的package包/類
/**
* Return the AsyncTaskExecutor to use for concurrent handling, or {@code null}.
*/
public AsyncTaskExecutor getExecutor() {
if (this.executor != null) {
return this.executor;
}
else if (this.executorName != null) {
Assert.state(this.beanFactory != null, "A BeanFactory is required to look up a task executor bean");
return this.beanFactory.getBean(this.executorName, AsyncTaskExecutor.class);
}
else {
return null;
}
}
示例12: taskExecutor
import org.springframework.core.task.AsyncTaskExecutor; //導入依賴的package包/類
/**
* Get a task executor for executing tasks asynchronously that don't need to be scheduled at a recurring rate.
*
* @param registry registry for spectator
* @param metacatProperties The metacat properties to get number of executor threads from.
* Likely best to do one more than number of CPUs
* @return The task executor the system to use
*/
@Bean
public AsyncTaskExecutor taskExecutor(final Registry registry, final MetacatProperties metacatProperties) {
final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(metacatProperties.getEvent().getBus().getExecutor().getThread().getCount());
executor.initialize();
RegistryUtil.registerThreadPool(registry, "metacat.event.pool", executor.getThreadPoolExecutor());
return executor;
}
示例13: WebAsyncTask
import org.springframework.core.task.AsyncTaskExecutor; //導入依賴的package包/類
/**
* Create a {@code WebAsyncTask} with a timeout value, an executor instance, and a Callable.
* @param timeout timeout value in milliseconds; ignored if {@code null}
* @param executor the executor to use
* @param callable the callable for concurrent handling
*/
public WebAsyncTask(Long timeout, AsyncTaskExecutor executor, Callable<V> callable) {
this(callable);
Assert.notNull(executor, "Executor must not be null");
this.executor = executor;
this.timeout = timeout;
}
示例14: getExecutor
import org.springframework.core.task.AsyncTaskExecutor; //導入依賴的package包/類
/**
* Return the AsyncTaskExecutor to use for concurrent handling,
* or {@code null} if none specified.
*/
public AsyncTaskExecutor getExecutor() {
if (this.executor != null) {
return this.executor;
}
else if (this.executorName != null) {
Assert.state(this.beanFactory != null, "BeanFactory is required to look up an executor bean by name");
return this.beanFactory.getBean(this.executorName, AsyncTaskExecutor.class);
}
else {
return null;
}
}
示例15: setUp
import org.springframework.core.task.AsyncTaskExecutor; //導入依賴的package包/類
@Before
public void setUp() {
this.servletRequest = new MockHttpServletRequest("GET", "/test");
this.servletRequest.setAsyncSupported(true);
this.servletResponse = new MockHttpServletResponse();
this.asyncWebRequest = new StandardServletAsyncWebRequest(servletRequest, servletResponse);
AsyncTaskExecutor executor = mock(AsyncTaskExecutor.class);
this.asyncManager = WebAsyncUtils.getAsyncManager(servletRequest);
this.asyncManager.setTaskExecutor(executor);
this.asyncManager.setAsyncWebRequest(this.asyncWebRequest);
}