本文整理汇总了Java中org.springframework.scheduling.annotation.Async类的典型用法代码示例。如果您正苦于以下问题:Java Async类的具体用法?Java Async怎么用?Java Async使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Async类属于org.springframework.scheduling.annotation包,在下文中一共展示了Async类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendEmail
import org.springframework.scheduling.annotation.Async; //导入依赖的package包/类
@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
isMultipart, isHtml, to, subject, content);
// Prepare message using a Spring helper
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
try {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
message.setTo(to);
message.setFrom(jHipsterProperties.getMail().getFrom());
message.setSubject(subject);
message.setText(content, isHtml);
javaMailSender.send(mimeMessage);
log.debug("Sent email to User '{}'", to);
} catch (Exception e) {
log.warn("Email could not be sent to user '{}'", to, e);
}
}
示例2: scheduleItems
import org.springframework.scheduling.annotation.Async; //导入依赖的package包/类
@Async
@Override
public Future<List<GetPrizeDTO>> scheduleItems(ScheduleItem item) throws InterruptedException {
log.info("Start Schedule with : " +item.getRecipientID());
log.info("query Type " + item.getQueryType());
Future<List<GetPrizeDTO>> result = new AsyncResult<>(new ArrayList<>());
if(item.getQueryType() == ConstantUtil.NORMAL_QUERY) {
result = new AsyncResult<>(resultService.findPrizeByResultType(item.getLotteryType(), item.getParam().toArray(new String[]{})));
} else if(item.getQueryType() == ConstantUtil.CODE_RANGE_QUERY) {
result = new AsyncResult<>(resultService.findPrizesByCode(item.getParam().get(0), item.getParam().get(1), item.getParam().get(2), item.getLotteryType()));
} else if(item.getQueryType() == ConstantUtil.POINT_RANGE_QUERY) {
result = new AsyncResult<>(resultService.findPrizesByPoints(item.getParam().get(0), item.getParam().get(1), item.getParam().get(2), item.getLotteryType()));
}
// remove from db after finding result.
deleteScheduleItem(item.getRecipientID());
return result;
}
示例3: retrieveStateAndSend
import org.springframework.scheduling.annotation.Async; //导入依赖的package包/类
@Override
@Async
@SuppressWarnings("unchecked")
public void retrieveStateAndSend(final Identifier id, final Class aClass) {
LOGGER.debug("Synchronizing on {} and {}...", id, aClass);
synchronized (lockObject) {
LOGGER.debug("Thread locked on {} and {}...!", id, aClass);
final List<JpaGroup> groups;
if (Jvm.class.getName().equals(aClass.getName())) {
final JpaJvm jvm = jvmCrudService.getJvm(id);
groups = jvm.getGroups();
} else if (WebServer.class.getName().equals(aClass.getName())) {
final JpaWebServer webServer = webServerCrudService.getWebServerAndItsGroups(id.getId());
groups = webServer.getGroups();
} else {
final String errMsg = "Invalid class parameter: " + aClass.getName() + "!";
LOGGER.error(errMsg);
throw new GroupStateNotificationServiceException(errMsg);
}
fetchStates(groups, true);
}
LOGGER.debug("Thread locked on {} and {} released!", id, aClass);
}
示例4: sendEmail
import org.springframework.scheduling.annotation.Async; //导入依赖的package包/类
@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
isMultipart, isHtml, to, subject, content);
// Prepare message using a Spring helper
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
try {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
message.setTo(to);
message.setFrom(jHipsterProperties.getMail().getFrom());
message.setSubject(subject);
message.setText(content, isHtml);
javaMailSender.send(mimeMessage);
log.debug("Sent email to User '{}'", to);
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.warn("Email could not be sent to user '{}'", to, e);
} else {
log.warn("Email could not be sent to user '{}': {}", to, e.getMessage());
}
}
}
示例5: sendMailWithNewPassword
import org.springframework.scheduling.annotation.Async; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Async
@Override
public void sendMailWithNewPassword(
@NotBlank @Email final String email,
@NotBlank final String newPassword
) {
log.info("Called with e-mail {}, newPassword {}", email, newPassword);
try {
final JavaMailSenderImpl sender = new JavaMailSenderImpl();
final MimeMessage message = sender.createMimeMessage();
final MimeMessageHelper helper = new MimeMessageHelper(message);
helper.setTo(email);
helper.setSubject("Recover password");
helper.setText("Your new password: " + "<b>" + newPassword + "</b>", true);
sendMail(message);
} catch (MessagingException e) {
e.printStackTrace();
}
}
示例6: send
import org.springframework.scheduling.annotation.Async; //导入依赖的package包/类
/**
* Sends an email message asynchronously through SendGrid.
* Status Code: 202 - ACCEPTED: Your message is both valid, and queued to be delivered.
*
* @param from email address from which the message will be sent.
* @param recipient array of strings containing the recipients of the message.
* @param subject subject header field.
* @param text content of the message.
*/
@Async
public void send(String from, String recipient, String replyTo, String subject, String text) throws IOException {
Email emailFrom = new Email(from);
String emailSubject = subject;
Email emailTo = new Email(recipient);
Content emailContent = new Content("text/html", text);
Mail mail = new Mail(emailFrom, emailSubject, emailTo, emailContent);
if (!replyTo.isEmpty()) {
Email emailReplyTo = new Email(replyTo);
mail.setReplyTo(emailReplyTo);
}
SendGrid sg = new SendGrid(sendgridApiKey);
Request request = new Request();
request.setMethod(Method.POST);
request.setEndpoint("mail/send");
request.setBody(mail.build());
sg.api(request);
}
示例7: addEmployee
import org.springframework.scheduling.annotation.Async; //导入依赖的package包/类
@Async
@Override
public void addEmployee(EmployeeForm empForm) {
Employee emp = new Employee();
emp.setDeptId(empForm.getEmpId());
emp.setFirstName(empForm.getFirstName());
emp.setLastName(empForm.getLastName());
emp.setAge(empForm.getAge());
emp.setBirthday(empForm.getBirthday());
emp.setEmail(empForm.getEmail());
emp.setDeptId(empForm.getDeptId());
emp.setEmpId(empForm.getEmpId());
try {
System.out.println("service:addEmployee task executor: " + Thread.currentThread().getName());
System.out.println("processing for 1000 ms");
System.out.println("addEmployee @Async login: " + SecurityContextHolder.getContext().getAuthentication().getPrincipal());
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
employeeDaoImpl.addEmployeeBySJI(emp);
}
示例8: handleExternalOutputMessage
import org.springframework.scheduling.annotation.Async; //导入依赖的package包/类
@Async
@Override
public void handleExternalOutputMessage(final ExternalCommunicatorMessage message) {
LOG.debug("Received request for external out message [{}]", message);
final Long messageFlowId = getMessageFlowId(message.getTransferId());
final Long configId = getActiveConfig(messageFlowId);
final Map<String, InternalObject> businessObjects = new HashMap<>();
message.getBusinessObjects().stream().forEachOrdered(bo -> {
final Map<String, InternalField> fields = new HashMap<>();
bo.getFields().stream().forEachOrdered(field -> {
fields.put(field.getName(), new InternalField(field.getName(),
DataType.valueOf(field.getType()), field.getValue()));
});
businessObjects.put(bo.getName(), new InternalObject(bo.getName(), fields));
});
composeSupervisorActor.tell(new ComposeMessageCreateCommand(message.getTransferId(),
new InternalData(businessObjects), configId), ActorRef.noSender());
}
示例9: start
import org.springframework.scheduling.annotation.Async; //导入依赖的package包/类
@Override
@Async("selectiejob")
public void start() {
LOGGER.info("start selectie run service: ");
BrpNu.set();
Thread.currentThread().setName("Selectie Job Runner");
final SelectieJobRunStatus status = selectieJobRunStatusService.newStatus();
Selectie selectie = null;
try {
selectie = selectieService.bepaalSelectie();
status.setStartDatum(new Date());
status.setSelectieRunId(selectie.getSelectierun().getId());
startSelectie(selectie);
LOGGER.info("einde selectie run service: " + selectie.getSelectierun().getId());
} finally {
status.setEindeDatum(new Date());
if (selectie != null) {
selectieService.eindeSelectie(selectie);
}
}
}
示例10: getTasksOfUser
import org.springframework.scheduling.annotation.Async; //导入依赖的package包/类
@Transactional
@Async
@Override
public Future<List<TaskDTO>> getTasksOfUser(final Long userId) {
final CompletableFuture<List<TaskDTO>> future = new CompletableFuture<>();
final TasksOfUserMessage.Request request = new TasksOfUserMessage.Request(userId);
PatternsCS.ask(userSupervisorActor, request, Global.TIMEOUT).toCompletableFuture()
.whenComplete((msg, exc) -> {
if (exc == null) {
future.complete(((TasksOfUserMessage.Response) msg).getTasks());
} else {
future.completeExceptionally(exc);
}
});
return future;
}
示例11: sendEmail
import org.springframework.scheduling.annotation.Async; //导入依赖的package包/类
@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
log.debug("Send e-mail[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
isMultipart, isHtml, to, subject, content);
// Prepare message using a Spring helper
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
try {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
message.setTo(to);
message.setFrom(jHipsterProperties.getMail().getFrom());
message.setSubject(subject);
message.setText(content, isHtml);
javaMailSender.send(mimeMessage);
log.debug("Sent e-mail to User '{}'", to);
} catch (Exception e) {
log.warn("E-mail could not be sent to user '{}'", to, e);
}
}
示例12: sendPasswordResetMail
import org.springframework.scheduling.annotation.Async; //导入依赖的package包/类
/**
* パスワードリセット案内メールを送信します。
*
* @param request パスワードリセット要求
*/
@Async
void sendPasswordResetMail(PasswordResetRequest request) {
SimpleMailMessage message = new SimpleMailMessage();
message.setReplyTo(appReply);
message.setTo(request.getMembership().getEmail());
message.setSubject("【パスワードリセット】Java研修 Go研修 OB・OG会");
message.setText(request.getMembership().getName() + " さん\n\n" +
"パスワードリセットの要求を受け付けました。\n" +
"下記 URL から 24 時間以内にパスワードリセットを行ってください。\n\n" +
appUrl + "/#!" + ResetPasswordView.VIEW_NAME + "/" + request.getToken() + "\n" +
"※トップページにリダイレクトされてしまう場合は、トップページを開いた画面 (タブ) のアドレス欄に" +
"上記 URL を張り付けて移動してください。\n\n" +
"本メールに関するお問合せ先: " + appReply + "\n" +
"Java研修 Go研修 OB・OG会");
try {
mailSender.send(message);
} catch (MailException e) {
exceptionHandler.accept(e);
}
}
示例13: asyncCreateInstance
import org.springframework.scheduling.annotation.Async; //导入依赖的package包/类
@Async
@Override
public void asyncCreateInstance(DeploymentServiceImpl deploymentService, ServiceInstance serviceInstance,
Map<String, String> parameters, Plan plan, PlatformService platformService) {
progressService.startJob(serviceInstance);
try {
deploymentService.syncCreateInstance(serviceInstance, parameters, plan, platformService);
} catch (Exception e) {
progressService.failJob(serviceInstance,
"Internal error during Instance creation, please contact our support.");
log.error("Exception during Instance creation", e);
return;
}
progressService.succeedProgress(serviceInstance);
}
示例14: sendEmail
import org.springframework.scheduling.annotation.Async; //导入依赖的package包/类
@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
log.debug("Send e-mail[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
isMultipart, isHtml, to, subject, content);
// Prepare message using a Spring helper
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
try {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
message.setTo(to);
message.setFrom(jHipsterProperties.getMail().getFrom());
message.setSubject(subject);
message.setText(content, isHtml);
javaMailSender.send(mimeMessage);
log.debug("Sent e-mail to User '{}'", to);
} catch (Exception e) {
log.warn("E-mail could not be sent to user '{}', exception is: {}", to, e.getMessage());
}
}
示例15: createThumbnail
import org.springframework.scheduling.annotation.Async; //导入依赖的package包/类
@Async
public String createThumbnail(UserFile userFile) {
String path = userFile.getPath();
Path originalImagePath = Paths.get(properties.getUploadFileRootPath(), path);
try {
BufferedImage originalImage = ImageIO.read(originalImagePath.toFile());
if (originalImage != null) {
BufferedImage thumbnailImage = this.createThumbnailImage(originalImage, 300, 200);
String ext = path.substring(path.lastIndexOf(".") + 1);
Path thumbNailPath = Paths.get(properties.getUploadFileRootPath(), userFile.getThumbnailPath());
ImageIO.write(thumbnailImage, ext, Files.newOutputStream(thumbNailPath));
return thumbNailPath.toString();
}
} catch (IOException e) {
logger.error("Failed to create thumbnail of '{}'", path);
}
return "";
}