本文整理汇总了Java中org.springframework.core.task.SimpleAsyncTaskExecutor类的典型用法代码示例。如果您正苦于以下问题:Java SimpleAsyncTaskExecutor类的具体用法?Java SimpleAsyncTaskExecutor怎么用?Java SimpleAsyncTaskExecutor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SimpleAsyncTaskExecutor类属于org.springframework.core.task包,在下文中一共展示了SimpleAsyncTaskExecutor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteFiles
import org.springframework.core.task.SimpleAsyncTaskExecutor; //导入依赖的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;
}
示例2: taskExecutor
import org.springframework.core.task.SimpleAsyncTaskExecutor; //导入依赖的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
示例3: getAsyncExecutor
import org.springframework.core.task.SimpleAsyncTaskExecutor; //导入依赖的package包/类
@Override
public Executor getAsyncExecutor() {
if (properties.isEnabled()) {
ThreadPoolTaskExecutor executor = null;
try {
executor = beanFactory.getBean(ThreadPoolTaskExecutor.class);
} catch (NoUniqueBeanDefinitionException e) {
executor = beanFactory.getBean(DEFAULT_TASK_EXECUTOR_BEAN_NAME, ThreadPoolTaskExecutor.class);
} catch (NoSuchBeanDefinitionException ex) {
}
if (executor != null) {
log.info("use default TaskExecutor ...");
return executor;
} else {
throw new BeanCreationException("Expecting a 'ThreadPoolTaskExecutor' exists, but was 'null'");
}
} else {
log.info(
"'AsyncExecutorConfiguration' is disabled, so create 'SimpleAsyncTaskExecutor' with 'threadNamePrefix' - '{}'",
properties.getThreadNamePrefix());
return new SimpleAsyncTaskExecutor(properties.getThreadNamePrefix());
}
}
示例4: setUp
import org.springframework.core.task.SimpleAsyncTaskExecutor; //导入依赖的package包/类
@Before
public void setUp() {
ReflectionTestUtils.setField(
instance2Test,
"hwAdapter_Rest",
mk_hwAdapter);
//~ INIT ONCE ~~~~~~~~~~~~~~
if(initialized)return ;
initialized = true;
ReflectionTestUtils.setField(
instance2Test,
"asyncExecutor",
new SimpleAsyncTaskExecutor("testBulbsHwService_"));
ReflectionTestUtils.setField(new BulbsCoreEventProcessor(), "eventStore",
mk_eventStore);
serviceLocator = new DomainServiceLocator();
ReflectionTestUtils.setField(serviceLocator, "instance", mk_domainServiceLocator);
}
示例5: taskExecutor
import org.springframework.core.task.SimpleAsyncTaskExecutor; //导入依赖的package包/类
/**
* Create the task executor which will be used for multi-threading
*
* @return TaskExecutor
*/
@Bean
public TaskExecutor taskExecutor() {
SimpleAsyncTaskExecutor asyncTaskExecutor = new SimpleAsyncTaskExecutor("spring_batch");
asyncTaskExecutor.setConcurrencyLimit(SimpleAsyncTaskExecutor.NO_CONCURRENCY);
return asyncTaskExecutor;
}
开发者ID:blackducksoftware,项目名称:hub-fortify-ssc-integration-service,代码行数:12,代码来源:SpringConfiguration.java
示例6: taskExecutor
import org.springframework.core.task.SimpleAsyncTaskExecutor; //导入依赖的package包/类
@Test
public void taskExecutor() throws Exception {
URI uri = new URI("ws://localhost/abc");
this.wsClient.setTaskExecutor(new SimpleAsyncTaskExecutor());
WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();
assertNotNull(session);
}
示例7: doHandshakeWithTaskExecutor
import org.springframework.core.task.SimpleAsyncTaskExecutor; //导入依赖的package包/类
@Test
public void doHandshakeWithTaskExecutor() throws Exception {
WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
headers.setSecWebSocketProtocol(Arrays.asList("echo"));
this.client.setTaskExecutor(new SimpleAsyncTaskExecutor());
this.wsSession = this.client.doHandshake(new TextWebSocketHandler(), headers, new URI(this.wsUrl)).get();
assertEquals(this.wsUrl, this.wsSession.getUri().toString());
assertEquals("echo", this.wsSession.getAcceptedProtocol());
}
示例8: createRequestFactory
import org.springframework.core.task.SimpleAsyncTaskExecutor; //导入依赖的package包/类
@Override
protected AsyncClientHttpRequestFactory createRequestFactory() {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
AsyncListenableTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor();
requestFactory.setTaskExecutor(taskExecutor);
return requestFactory;
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:8,代码来源:BufferedSimpleAsyncHttpRequestFactoryTests.java
示例9: step1
import org.springframework.core.task.SimpleAsyncTaskExecutor; //导入依赖的package包/类
@Bean
public Step step1() {
return stepBuilderFactory.get("step1")
.<Bracket, Bracket>chunk(10000)
.reader(itemReader())
.processor(itemProcessor())
.writer(itemWriter(null))
.taskExecutor(new SimpleAsyncTaskExecutor())
.build();
}
示例10: setup
import org.springframework.core.task.SimpleAsyncTaskExecutor; //导入依赖的package包/类
@Before
public void setup() {
executor = new SimpleAsyncTaskExecutor();
recorder = LogbackRecorder.forClass(MockEnvironment.class).reset().capture("ALL");
environment = new MockEnvironment();
recorder.release();
config = spy(new TestAsyncSpringLiquibase(executor, environment));
recorder = LogbackRecorder.forClass(AsyncSpringLiquibase.class).reset().capture("ALL");
}
示例11: taskExecutor
import org.springframework.core.task.SimpleAsyncTaskExecutor; //导入依赖的package包/类
/**
* @return task executor
*
* @see https://jira.spring.io/browse/BATCH-2269
*/
@Bean
public TaskExecutor taskExecutor() {
return new SimpleAsyncTaskExecutor() {
private static final long serialVersionUID = 1L;
@Override
protected void doExecute(Runnable task) {
/* Gets the jobExecution of the configuration thread */
JobExecution jobExecution = JobSynchronizationManager
.getContext()
.getJobExecution();
super.doExecute(new Runnable() {
@Override
public void run() {
JobSynchronizationManager.register(jobExecution);
try {
task.run();
} finally {
JobSynchronizationManager.release();
}
}
});
}
};
}
示例12: afterPropertiesSet
import org.springframework.core.task.SimpleAsyncTaskExecutor; //导入依赖的package包/类
/**
* Initializes the task executor adapter. Expects the delegate to be set. If no
* {@link #setTaskExecutor(org.springframework.core.task.TaskExecutor) taskExecutor} is
* provided will create a default one using {@link org.springframework.core.task.SimpleAsyncTaskExecutor}.
*/
public void afterPropertiesSet() throws Exception {
Assert.notNull(delegate, "delegate SpaceDataEventListener must not be null");
if (taskExecutor == null) {
SimpleAsyncTaskExecutor simpleAsyncTaskExecutor = new SimpleAsyncTaskExecutor();
simpleAsyncTaskExecutor.setDaemon(true);
taskExecutor = simpleAsyncTaskExecutor;
}
}
示例13: networkPool
import org.springframework.core.task.SimpleAsyncTaskExecutor; //导入依赖的package包/类
@Bean(name = "networkPool")
public SimpleAsyncTaskExecutor networkPool()
{
SimpleAsyncTaskExecutor pool = new SimpleAsyncTaskExecutor();
pool.setThreadPriority(Thread.NORM_PRIORITY + 1);
return pool;
}
示例14: getAsyncRestTemplate
import org.springframework.core.task.SimpleAsyncTaskExecutor; //导入依赖的package包/类
private AsyncRestTemplate getAsyncRestTemplate() {
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
factory.setTaskExecutor(new SimpleAsyncTaskExecutor());
factory.setConnectTimeout(gorouterProperties.getConnectTimeout());
factory.setReadTimeout(gorouterProperties.getReadTimeout());
return new AsyncRestTemplate(factory);
}
示例15: CSVSerializerTest
import org.springframework.core.task.SimpleAsyncTaskExecutor; //导入依赖的package包/类
public CSVSerializerTest() {
this.serializer = new CSVSerializer();
TaskExecutor executor = new SimpleAsyncTaskExecutor();
ReflectionTestUtils.setField(serializer, "executor", executor);
ReflectionTestUtils.setField(serializer, "defaultTextEnclosure", "\"");
ReflectionTestUtils.setField(serializer, "defaultEscapeChar", "\u0000");
}