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