当前位置: 首页>>代码示例>>Java>>正文


Java Async类代码示例

本文整理汇总了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);
    }
}
 
开发者ID:deepu105,项目名称:spring-io,代码行数:20,代码来源:MailService.java

示例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;
}
 
开发者ID:kyawswa,项目名称:myanmarlottery,代码行数:18,代码来源:ScheduleServiceImpl.java

示例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);
}
 
开发者ID:cerner,项目名称:jwala,代码行数:24,代码来源:GroupStateNotificationServiceImpl.java

示例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());
        }
    }
}
 
开发者ID:oktadeveloper,项目名称:jhipster-microservices-example,代码行数:24,代码来源:MailService.java

示例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();
    }
}
 
开发者ID:JonkiPro,项目名称:REST-Web-Services,代码行数:28,代码来源:MailServiceImpl.java

示例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);
}
 
开发者ID:Code4SocialGood,项目名称:c4sg-services,代码行数:32,代码来源:AsyncEmailServiceImpl.java

示例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);
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:25,代码来源:EmployeeServiceImpl.java

示例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());
}
 
开发者ID:stefanstaniAIM,项目名称:IPPR2016,代码行数:22,代码来源:ExternalCommunicatorServiceImpl.java

示例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);
        }
    }
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:22,代码来源:SelectieRunJobServiceImpl.java

示例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;
}
 
开发者ID:stefanstaniAIM,项目名称:IPPR2016,代码行数:20,代码来源:ProcessServiceImpl.java

示例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);
    }
}
 
开发者ID:mraible,项目名称:devoxxus-jhipster-microservices-demo,代码行数:20,代码来源:MailService.java

示例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);
    }
}
 
开发者ID:JavaTrainingCourse,项目名称:obog-manager,代码行数:26,代码来源:MailService.java

示例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);
}
 
开发者ID:evoila,项目名称:cfsummiteu2017,代码行数:18,代码来源:AsyncDeploymentServiceImpl.java

示例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());
    }
}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:20,代码来源:MailService.java

示例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 "";
}
 
开发者ID:spring-sprout,项目名称:osoon,代码行数:21,代码来源:UserFileService.java


注:本文中的org.springframework.scheduling.annotation.Async类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。