Here are the examples of the java api @org.springframework.scheduling.annotation.Async taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
754 Examples
19
View Source File : AsyncTaskService.java
License : GNU General Public License v3.0
Project Creator : zhonghuasheng
License : GNU General Public License v3.0
Project Creator : zhonghuasheng
@Async
public void executeAsyncAddTask(int i) {
System.out.println(i + i);
}
19
View Source File : AsyncTaskService.java
License : GNU General Public License v3.0
Project Creator : zhonghuasheng
License : GNU General Public License v3.0
Project Creator : zhonghuasheng
/**
* @Async注解在方法上表明该方法是异步执行,如果注解在类上,表明该类下的所有方法都是异步执行
* @param i
*/
@Async
public void executeAsyncTask(int i) {
System.out.println("Execute async task: " + i);
}
19
View Source File : MarketServiceImpl.java
License : MIT License
Project Creator : yizzuide
License : MIT License
Project Creator : yizzuide
@Async
public void process() {
}
19
View Source File : AsyncTask.java
License : MIT License
Project Creator : yidao620c
License : MIT License
Project Creator : yidao620c
@Async
public ListenableFuture<String> expensiveOperation(String message) {
int millis = (int) (Math.random() * 5 * 1000);
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
}
String result = message + " executed by " + Thread.currentThread().getName() + " for " + millis + " ms";
logger.info("task result {}", result);
return new AsyncResult<String>(result);
}
19
View Source File : AsyncTask.java
License : MIT License
Project Creator : yidao620c
License : MIT License
Project Creator : yidao620c
@Async
public void dealNoReturnTask() {
logger.info("返回值为void的异步调用开始" + Thread.currentThread().getName());
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
logger.info("返回值为void的异步调用结束" + Thread.currentThread().getName());
}
19
View Source File : AsyncTask.java
License : Apache License 2.0
Project Creator : xuwujing
License : Apache License 2.0
Project Creator : xuwujing
/*
* 可以利用Future<T>来进行回调
*/
@Async
public Future<String> test1() {
System.out.println("开始一");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("结束一");
return new AsyncResult<>("任务一完成");
}
19
View Source File : AsyncTask.java
License : Apache License 2.0
Project Creator : xuwujing
License : Apache License 2.0
Project Creator : xuwujing
@Async
public Future<String> test2() {
System.out.println("开始二");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("结束二");
return new AsyncResult<>("任务二完成");
}
19
View Source File : AsyncTask.java
License : Apache License 2.0
Project Creator : xuwujing
License : Apache License 2.0
Project Creator : xuwujing
@Async
public Future<String> test3() {
System.out.println("开始三");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("结束三");
return new AsyncResult<>("任务三完成");
}
19
View Source File : CtcController.java
License : Apache License 2.0
Project Creator : xunibidev
License : Apache License 2.0
Project Creator : xunibidev
/**
* 发送用户付款通知
*/
@Async
private void sendNotification() {
try {
String[] adminList = admins.split(",");
for (int i = 0; i < adminList.length; i++) {
sendEmailMsg(adminList[i], "收到用户付款标记", "用户付款通知");
}
} catch (Exception e) {
MessageResult result;
try {
String[] phones = adminPhones.split(",");
if (phones.length > 0) {
result = smsProvider.sendSingleMessage(phones[0], "收到用户付款标记");
if (result.getCode() != 0) {
if (phones.length > 1) {
smsProvider.sendSingleMessage(phones[1], "收到用户付款标记");
}
}
}
} catch (Exception e1) {
e1.printStackTrace();
}
e.printStackTrace();
}
}
19
View Source File : MailService.java
License : Apache License 2.0
Project Creator : xm-online
License : Apache License 2.0
Project Creator : xm-online
/**
* Send mail with raw subject, from and content.
*
* @param content the content of email
* @param subject the raw subject
* @param email the to email
* @param from the from email
*/
@Async
public void sendEmailWithContent(TenantKey tenantKey, String content, String subject, String email, String from) {
initAndSendEmail(tenantKey, content, subject, email, MdcUtils.generateRid(), from, null);
}
19
View Source File : MailService.java
License : Apache License 2.0
Project Creator : xm-online
License : Apache License 2.0
Project Creator : xm-online
/**
* Send mail with raw subject, from and content.
*
* @param content the content of email
* @param subject the raw subject
* @param email the to email
* @param from the from email
* @param attachmentFilename the name of the attachment as it will appear in the mail
* @param dataSource the {@code javax.activation.DataSource} to take the content from, determining the InputStream
* and the content type
*/
@Async
public void sendEmailWithContentAndAttachments(TenantKey tenantKey, String content, String subject, String email, String from, String attachmentFilename, InputStreamSource dataSource) {
initAndSendEmail(tenantKey, content, subject, email, MdcUtils.generateRid(), from, Map.of(attachmentFilename, dataSource));
}
19
View Source File : TimelineEventProducer.java
License : Apache License 2.0
Project Creator : xm-online
License : Apache License 2.0
Project Creator : xm-online
/**
* Send event to kafka.
*
* @param topic the kafka topic
* @param content the event content
*/
@Async
public void send(String topic, String content) {
try {
if (!StringUtils.isBlank(content)) {
log.debug("Sending kafka event with data {} to topic {}", content, topic);
template.send(topic, content);
}
} catch (Exception e) {
log.error("Error send timeline event", e);
throw e;
}
}
19
View Source File : PrivilegeInspector.java
License : Apache License 2.0
Project Creator : xm-online
License : Apache License 2.0
Project Creator : xm-online
/**
* Scan for permission annotations and send event to kafka.
*/
@Async
public void readPrivileges(String eventId) {
eventProducer.sendEvent(eventId, scanner.scan());
}
19
View Source File : TaskFactory.java
License : MIT License
Project Creator : xkcoding
License : MIT License
Project Creator : xkcoding
/**
* 模拟3秒的异步任务
*/
@Async
public Future<Boolean> asyncTask3() throws InterruptedException {
doTask("asyncTask3", 3);
return new AsyncResult<>(Boolean.TRUE);
}
19
View Source File : TaskFactory.java
License : MIT License
Project Creator : xkcoding
License : MIT License
Project Creator : xkcoding
/**
* 模拟5秒的异步任务
*/
@Async
public Future<Boolean> asyncTask1() throws InterruptedException {
doTask("asyncTask1", 5);
return new AsyncResult<>(Boolean.TRUE);
}
19
View Source File : TaskFactory.java
License : MIT License
Project Creator : xkcoding
License : MIT License
Project Creator : xkcoding
/**
* 模拟2秒的异步任务
*/
@Async
public Future<Boolean> asyncTask2() throws InterruptedException {
doTask("asyncTask2", 2);
return new AsyncResult<>(Boolean.TRUE);
}
19
View Source File : NotifyService.java
License : GNU General Public License v3.0
Project Creator : wlhbdp
License : GNU General Public License v3.0
Project Creator : wlhbdp
/**
* 微信模版消息通知,带跳转
* <p>
* 该方法会尝试从数据库获取缓存的FormId去发送消息
*
* @param touser 接收者openId
* @param notifyType 通知类别,通过该枚举值在配置文件中获取相应的模版ID
* @param params 通知模版内容里的参数,类似"您的验证码为{1}"中{1}的值
* @param page 点击消息跳转的页面
*/
@Async
public void notifyWxTemplate(String touser, NotifyType notifyType, String[] params, String page) {
if (wxTemplateSender == null)
return;
String templateId = getTemplateId(notifyType, wxTemplate);
wxTemplateSender.sendWechatMsg(touser, templateId, params, page);
}
19
View Source File : NotifyService.java
License : GNU General Public License v3.0
Project Creator : wlhbdp
License : GNU General Public License v3.0
Project Creator : wlhbdp
/**
* 短信消息通知
*
* @param phoneNumber 接收通知的电话号码
* @param message 短消息内容,这里短消息内容必须已经在短信平台审核通过
*/
@Async
public void notifySms(String phoneNumber, String message) {
if (smsSender == null)
return;
smsSender.send(phoneNumber, message);
}
19
View Source File : NotifyService.java
License : GNU General Public License v3.0
Project Creator : wlhbdp
License : GNU General Public License v3.0
Project Creator : wlhbdp
/**
* 微信模版消息通知,不跳转
* <p>
* 该方法会尝试从数据库获取缓存的FormId去发送消息
*
* @param touser 接收者openId
* @param notifyType 通知类别,通过该枚举值在配置文件中获取相应的模版ID
* @param params 通知模版内容里的参数,类似"您的验证码为{1}"中{1}的值
*/
@Async
public void notifyWxTemplate(String touser, NotifyType notifyType, String[] params) {
if (wxTemplateSender == null)
return;
String templateId = getTemplateId(notifyType, wxTemplate);
wxTemplateSender.sendWechatMsg(touser, templateId, params);
}
19
View Source File : NotifyService.java
License : GNU General Public License v3.0
Project Creator : wlhbdp
License : GNU General Public License v3.0
Project Creator : wlhbdp
/**
* 短信模版消息通知
*
* @param phoneNumber 接收通知的电话号码
* @param notifyType 通知类别,通过该枚举值在配置文件中获取相应的模版ID
* @param params 通知模版内容里的参数,类似"您的验证码为{1}"中{1}的值
*/
@Async
public void notifySmsTemplate(String phoneNumber, NotifyType notifyType, String[] params) {
if (smsSender == null) {
return;
}
String templateIdStr = getTemplateId(notifyType, smsTemplate);
if (templateIdStr == null) {
return;
}
int templateId = Integer.parseInt(templateIdStr);
smsSender.sendWithTemplate(phoneNumber, templateId, params);
}
19
View Source File : FlairCachingService.java
License : Apache License 2.0
Project Creator : viz-centric
License : Apache License 2.0
Project Creator : viz-centric
@Async
public void putResultAsync(String query, String connectionLinkId, String result, CacheParams cacheParams) {
putResult(query, connectionLinkId, result, cacheParams);
}
19
View Source File : AsyncTaskService.java
License : Apache License 2.0
Project Creator : V-I-C-T-O-R
License : Apache License 2.0
Project Creator : V-I-C-T-O-R
@Async
public void executeAsyncTask() {
logger.info("执行异步任务");
collectData.poll(queue);
}
19
View Source File : AsyncTaskService.java
License : Apache License 2.0
Project Creator : V-I-C-T-O-R
License : Apache License 2.0
Project Creator : V-I-C-T-O-R
@Async
public void executeAsyncTask(Integer i) {
logger.info("执行异步任务: " + i);
collectData.poll(RedisInfoSubscriber.queue);
}
19
View Source File : DbBlockGenerator.java
License : Apache License 2.0
Project Creator : tianyaleixiaowu
License : Apache License 2.0
Project Creator : tianyaleixiaowu
/**
* sqlite根据block信息,执行sql
*/
@Async
public void sqliteSync() {
// 开始同步到sqlite
ApplicationContextProvider.publishEvent(new DbSyncEvent(""));
}
19
View Source File : UserService.java
License : Apache License 2.0
Project Creator : TFdream
License : Apache License 2.0
Project Creator : TFdream
@Async
public void doNoReturn() {
LOG.info("提交任务开始");
sleep(3000);
LOG.info("提交任务结束");
}
19
View Source File : UserService.java
License : Apache License 2.0
Project Creator : TFdream
License : Apache License 2.0
Project Creator : TFdream
@Async
public Future<String> getUserById(Long userId) {
LOG.info("查询用户信息开始, userId:{}", userId);
sleep(2000);
LOG.info("查询用户信息结束, userId:{}", userId);
return new AsyncResult<String>(String.format("userId:%s", userId));
}
19
View Source File : RssLoadService.java
License : MIT License
Project Creator : tarpha
License : MIT License
Project Creator : tarpha
@Async
public void asyncLoadRss() {
loadRss();
}
19
View Source File : SleuthBenchmarkingSpringApp.java
License : Apache License 2.0
Project Creator : spring-cloud-incubator
License : Apache License 2.0
Project Creator : spring-cloud-incubator
@Async
public Future<String> async() {
return this.pool.submit(() -> "async");
}
19
View Source File : PostServiceImpl.java
License : GNU General Public License v3.0
Project Creator : saysky
License : GNU General Public License v3.0
Project Creator : saysky
@Override
@Async
public void updatePostView(Long postId) {
postMapper.incrPostViews(postId);
}
19
View Source File : EmailClient.java
License : Apache License 2.0
Project Creator : rule-engine
License : Apache License 2.0
Project Creator : rule-engine
/**
* 异步发送邮件
* 注意:出现错误信息不会被显示页面
*
* @param params 模板参数
* @param replacedle 邮箱标题
* @param templateName 模板名称
* @param tos 发送给谁,可以是多个
*/
@Async
public void sendSimpleMailAsync(Object params, String replacedle, String templateName, String... tos) {
sendSimpleMail(params, replacedle, templateName, tos);
}
19
View Source File : CleanUpLogs.java
License : MIT License
Project Creator : RPCheung
License : MIT License
Project Creator : RPCheung
@Async
@Scheduled(cron = "${clean.cron}")
public void exec() {
log.info("定时任务启动");
cleanUpLogs("netty_trace");
cleanUpLogs("shadowsockets_error");
cleanUpLogs("shadowsockets_trace");
log.info("定时任务结束");
}
19
View Source File : ScheduledJob.java
License : MIT License
Project Creator : rickding
License : MIT License
Project Creator : rickding
@Service
@Async
public clreplaced ScheduledJob {
@Async
@Scheduled(cron = "0/19 * * * * ?")
public void scheduledCron() {
System.out.printf("scheduled cron: %s\n", new Date());
}
@Scheduled(fixedRate = 1000 * 29, initialDelay = 1000 * 30)
public void scheduledRate() {
System.out.printf("fixedRate: %s\n", new Date());
}
@Scheduled(fixedDelay = 1000 * 37, initialDelay = 1000 * 40)
public void scheduledDelay() {
System.out.printf("fixedDelay: %s\n", new Date());
}
}
19
View Source File : ScheduledJob.java
License : MIT License
Project Creator : rickding
License : MIT License
Project Creator : rickding
@Async
@Scheduled(cron = "0/19 * * * * ?")
public void scheduledCron() {
System.out.printf("scheduled cron: %s\n", new Date());
}
19
View Source File : HelloSchedule.java
License : MIT License
Project Creator : rickding
License : MIT License
Project Creator : rickding
@Service
@Async
public clreplaced HelloSchedule {
@Async
@Scheduled(cron = "0/5 * * * * *")
public void scheduled1() {
System.out.println(String.format("cron %d", System.currentTimeMillis()));
}
@Scheduled(fixedRate = 1000 * 7)
public void scheduled2() {
System.out.println(String.format("fixedRate %d", System.currentTimeMillis()));
}
@Scheduled(fixedDelay = 1000 * 11)
public void scheduled3() {
System.out.println(String.format("fixedDelay %d", System.currentTimeMillis()));
}
}
19
View Source File : ExecuteIntegrationHandlerImpl.java
License : Apache License 2.0
Project Creator : reportportal
License : Apache License 2.0
Project Creator : reportportal
@Async
public <// need for security context sharing into plugin
U> void supplyAsync(Supplier<U> supplier) {
supplier.get();
}
19
View Source File : ThreadService.java
License : MIT License
Project Creator : qinxuewu
License : MIT License
Project Creator : qinxuewu
@Async
public void clearAll() {
threadMapper.deleteAll();
}
19
View Source File : NotifyService.java
License : GNU Lesser General Public License v3.0
Project Creator : qiguliuxing
License : GNU Lesser General Public License v3.0
Project Creator : qiguliuxing
/**
* 微信模版消息通知,带跳转
* <p>
* 该方法会尝试从数据库获取缓存的FormId去发送消息
*
* @param touser
* 接收者openId
* @param notifyType
* 通知类别,通过该枚举值在配置文件中获取相应的模版ID
* @param params
* 通知模版内容里的参数,类似"您的验证码为{1}"中{1}的值
* @param page
* 点击消息跳转的页面
*/
@Async
public void notifyWxTemplate(String touser, NotifyType notifyType, String[] params, String page) {
if (wxTemplateSender == null)
return;
String templateId = getTemplateId(notifyType, wxTemplate);
wxTemplateSender.sendWechatMsg(touser, templateId, params, page);
}
19
View Source File : NotifyService.java
License : GNU Lesser General Public License v3.0
Project Creator : qiguliuxing
License : GNU Lesser General Public License v3.0
Project Creator : qiguliuxing
/**
* 短信模版消息通知
*
* @param phoneNumber
* 接收通知的电话号码
* @param notifyType
* 通知类别,通过该枚举值在配置文件中获取相应的模版ID
* @param params
* 通知模版内容里的参数,类似"您的验证码为{1}"中{1}的值
*/
@Async
public void notifySmsTemplate(String phoneNumber, NotifyType notifyType, String[] params) {
if (smsSender == null) {
return;
}
String templateIdStr = getTemplateId(notifyType, smsTemplate);
if (templateIdStr == null) {
return;
}
int templateId = Integer.parseInt(templateIdStr);
smsSender.sendWithTemplate(phoneNumber, templateId, params);
}
19
View Source File : NotifyService.java
License : GNU Lesser General Public License v3.0
Project Creator : qiguliuxing
License : GNU Lesser General Public License v3.0
Project Creator : qiguliuxing
/**
* 发送ssl邮件
*
* @param subject
* 邮件标题
* @param content
* 邮件内容
*/
@Async
public void notifySslMail(String subject, String content) {
if (sslMailSender == null)
return;
sslMailSender.sendMails(subject, content);
}
19
View Source File : NotifyService.java
License : GNU Lesser General Public License v3.0
Project Creator : qiguliuxing
License : GNU Lesser General Public License v3.0
Project Creator : qiguliuxing
/**
* 微信模版消息通知,不跳转
* <p>
* 该方法会尝试从数据库获取缓存的FormId去发送消息
*
* @param touser
* 接收者openId
* @param notifyType
* 通知类别,通过该枚举值在配置文件中获取相应的模版ID
* @param params
* 通知模版内容里的参数,类似"您的验证码为{1}"中{1}的值
*/
@Async
public void notifyWxTemplate(String touser, NotifyType notifyType, String[] params) {
if (wxTemplateSender == null)
return;
String templateId = getTemplateId(notifyType, wxTemplate);
wxTemplateSender.sendWechatMsg(touser, templateId, params);
}
19
View Source File : NotifyService.java
License : GNU Lesser General Public License v3.0
Project Creator : qiguliuxing
License : GNU Lesser General Public License v3.0
Project Creator : qiguliuxing
/**
* 短信消息通知
*
* @param phoneNumber
* 接收通知的电话号码
* @param message
* 短消息内容,这里短消息内容必须已经在短信平台审核通过
*/
@Async
public void notifySms(String phoneNumber, String message) {
if (smsSender == null)
return;
smsSender.send(phoneNumber, message);
}
19
View Source File : StatefullTransactionalLoopService.java
License : GNU Affero General Public License v3.0
Project Creator : progilone
License : GNU Affero General Public License v3.0
Project Creator : progilone
@Async
public <T> void loopAsync(final List<T> enreplacedies, final long nbCommit, final boolean readonly, final LoopCallback<T> c) {
loop(enreplacedies, nbCommit, readonly, c);
}
19
View Source File : AbstractElasticsearchOperations.java
License : GNU Affero General Public License v3.0
Project Creator : progilone
License : GNU Affero General Public License v3.0
Project Creator : progilone
/**
* Indexation asynchrone de plusieurs enreplacedés
*
* @param identifiers
*/
@Async
@Transactional(readOnly = true)
public void indexAsync(final List<String> identifiers) {
index(identifiers);
}
19
View Source File : AbstractElasticsearchOperations.java
License : GNU Affero General Public License v3.0
Project Creator : progilone
License : GNU Affero General Public License v3.0
Project Creator : progilone
/**
* Indexation asynchrone
*
* @param identifier
*/
@Async
@Transactional(readOnly = true)
public void indexAsync(final String identifier) {
index(identifier);
}
19
View Source File : AbstractElasticsearchOperations.java
License : GNU Affero General Public License v3.0
Project Creator : progilone
License : GNU Affero General Public License v3.0
Project Creator : progilone
/**
* Suppression asynchrone
*
* @param enreplacedies
*/
@Async
public void deleteAsync(final Collection<T> enreplacedies) {
delete(enreplacedies);
}
19
View Source File : AbstractElasticsearchOperations.java
License : GNU Affero General Public License v3.0
Project Creator : progilone
License : GNU Affero General Public License v3.0
Project Creator : progilone
/**
* Suppression asynchrone
*
* @param enreplacedy
*/
@Async
public void deleteAsync(final T enreplacedy) {
delete(enreplacedy);
}
19
View Source File : AutomaticCheckService.java
License : GNU Affero General Public License v3.0
Project Creator : progilone
License : GNU Affero General Public License v3.0
Project Creator : progilone
/**
* Lance un contrôle sur une unité doreplacedentaire de façon asynchrone
* L'unité doreplacedentaire doit être complètement initialisée
*
* @param type
* @param doc
*/
@Async
public void asyncUnitCheck(final AutoCheckType type, final DocUnit doc, final String libraryId) {
if (type != null) {
final List<AutomaticCheckType> types = findCheckByType(Collections.singletonList(type));
asyncCheck(types, doc, libraryId);
}
}
19
View Source File : DepartmentServiceImpl.java
License : MIT License
Project Creator : PacktPublishing
License : MIT License
Project Creator : PacktPublishing
@Async
public Future<Department> readDepartment(Integer id) {
return new AsyncResult<>(departmentRepository.findById(id).orElse(new Department()));
}
19
View Source File : EmployeeServiceImpl.java
License : MIT License
Project Creator : PacktPublishing
License : MIT License
Project Creator : PacktPublishing
@Async
public Future<Employee> readEmployee(Integer empId) {
try {
System.out.println("service:readEmployee(empid) task executor: " + Thread.currentThread().getName());
System.out.println("processing for 2000 ms");
System.out.println("readEmployee @Async login: " + SecurityContextHolder.getContext().getAuthentication().getPrincipal());
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return new AsyncResult<>(employeeDaoImpl.getEmployee(empId));
}
19
View Source File : EmployeeServiceImpl.java
License : MIT License
Project Creator : PacktPublishing
License : MIT License
Project Creator : PacktPublishing
@Async
public Future<Employee> readEmployee(Integer id) {
return new AsyncResult<>(employeeRepository.findById(id).orElse(new Employee()));
}
See More Examples