java类org.springframework.scheduling.annotation.Async的实例源码

DataService.java 文件源码 项目:canal-mongo 阅读 32 收藏 0 点赞 0 评论 0
@Async("myTaskAsyncPool")
public Future<Integer> doAsyncTask(String tableName, List<EventData> dataList, String destination) {
    try {
        MDC.put("destination", destination);
        logger.info("thread: " + Thread.currentThread().getName() + " is doing job :" + tableName);
        for (EventData eventData : dataList) {
            SpringUtil.doEvent(eventData.getPath(), eventData.getDbObject());
        }
    } catch (Exception e) {
        logger.error("thread:" + Thread.currentThread().getName() + " get Exception", e);
        return new AsyncResult(0);
    }
    return new AsyncResult(1);
}
MailService.java 文件源码 项目:TorgCRM-Server 阅读 24 收藏 0 点赞 0 评论 0
@Async
public void sendEmailFromTemplate(User user, String templateName, String titleKey) {
    Locale locale = Locale.forLanguageTag(user.getLangKey());
    Context context = new Context(locale);
    context.setVariable(USER, user);
    context.setVariable(BASE_URL, jHipsterProperties.getMail().getBaseUrl());
    String content = templateEngine.process(templateName, context);
    String subject = messageSource.getMessage(titleKey, null, locale);
    sendEmail(user.getEmail(), subject, content, false, true);

}
AuthenticationController.java 文件源码 项目:Your-Microservice 阅读 31 收藏 0 点赞 0 评论 0
/**
 * saveTokenHistory
 *
 * @param token Token to re-verify to obtain Claims Set to Persist as a Token History Element.
 */
@Async
protected void saveTokenHistory(String token) {
    try {
        /**
         * Generate a Token History Entry based upon our Current Supplied Token.
         */
        JWTClaimsSet claimsSet = yourMicroserviceToken.verifyToken(token);
        if (claimsSet == null) {
            LOGGER.warn("Unable to Verify Token to retrieve ClaimsSet to Persist Token History, Ignoring.");
            return;
        }
        /**
         * Instantiate the Token History Entity.
         */
        YourEntityTokenHistory yourEntityTokenHistory = new YourEntityTokenHistory();
        yourEntityTokenHistory.setJti(claimsSet.getJWTID());
        yourEntityTokenHistory.setSubject(claimsSet.getSubject());
        yourEntityTokenHistory.setStatus(YourEntityTokenStatus.ACTIVE);
        yourEntityTokenHistory.setIssuedAt(claimsSet.getIssueTime());
        yourEntityTokenHistory.setExpiration(claimsSet.getExpirationTime());
        yourEntityTokenHistory.setNotUsedBefore(claimsSet.getNotBeforeTime());
        yourEntityTokenHistory.setLastUsed(claimsSet.getIssueTime());
        yourEntityTokenHistory.setUsageCount(1L);
        /**
         * Persist the Entity.
         */
        yourEntityTokenHistory = identityProviderEntityManager.createTokenHistory(yourEntityTokenHistory);
        if (yourEntityTokenHistory == null) {
            LOGGER.warn("Unable to Persist Token History Entity, Ignoring.");
        }
    } catch (YourMicroserviceInvalidTokenException ite) {
        LOGGER.warn("Invalid Your Microservice Token Exception:'{}', Encountered while attempting " +
                "to persist Token History Entity.", ite.getMessage(), ite);
    }
}
DynamicLoadClassAsync.java 文件源码 项目:daros-dynamic 阅读 19 收藏 0 点赞 0 评论 0
@Async("register")
public CompletableFuture<List<String>> compileGroovy(String path) {
    logger.info("Start compile groovy file: " + path);
    List<String> listClassName = DynamicUtil.compileGroovyFile(path);

    try {
        Thread.sleep(1000L);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    logger.info("Complete compile groovy file: " + path);
    return CompletableFuture.completedFuture(listClassName);
}
BaseService.java 文件源码 项目:device-bacnet 阅读 31 收藏 0 点赞 0 评论 0
@Async
public void attemptToInitialize() {

    // count the attempt
    setInitAttempts(getInitAttempts() + 1);
    logger.debug("initialization attempt " + getInitAttempts());

    // first - get the service information or register service with metadata
    if(getService() != null) {
        // if we were able to get the service data we're registered
        setRegistered(true);
        // second - invoke any custom initialization method 
        setInitialized(initialize(getServiceId()));
    }

    // if both are successful, then we're done
    if(isRegistered() && isInitialized()) {
        logger.info("initialization successful.");
    } else {
        // otherwise see if we need to keep going
        if((getInitRetries() == 0) || (getInitAttempts() < getInitRetries())) {
            logger.debug("initialization unsuccessful. sleeping " + getInitInterval());
            try {
                Thread.sleep(getInitInterval());
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
            // start up the next thread
            attemptToInitialize();

        } else {
            // here, we've failed and run out of retries, so just be done.
            logger.info("initialization unsuccessful after " + getInitAttempts() + " attempts.  Giving up.");
            // TODO: what do we do here? exit?
            Application.exit(-1);
        }
    } 
}
BaseService.java 文件源码 项目:device-bluetooth 阅读 29 收藏 0 点赞 0 评论 0
@Async
public void attemptToInitialize() {

  // count the attempt
  setInitAttempts(getInitAttempts() + 1);
  logger.debug("initialization attempt " + getInitAttempts());

  // first - get the service information or register service with metadata
  if (getService() != null) {
    // if we were able to get the service data we're registered
    setRegistered(true);
    // second - invoke any custom initialization method
    setInitialized(initialize(getServiceId()));
  }

  // if both are successful, then we're done
  if (isRegistered() && isInitialized()) {
    logger.info("initialization successful.");
  } else {
    // otherwise see if we need to keep going
    if ((getInitRetries() == 0) || (getInitAttempts() < getInitRetries())) {
      logger.debug("initialization unsuccessful. sleeping " + getInitInterval());
      try {
        Thread.sleep(getInitInterval());
      } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
      }
      // start up the next thread
      attemptToInitialize();

    } else {
      // here, we've failed and run out of retries, so just be done.
      logger.info("initialization unsuccessful after " + getInitAttempts()
          + " attempts.  Giving up.");
      // TODO: what do we do here? exit?
      Application.exit(-1);
    }
  }
}
BaseService.java 文件源码 项目:device-mqtt 阅读 29 收藏 0 点赞 0 评论 0
@Async
public void attemptToInitialize() {

  // count the attempt
  setInitAttempts(getInitAttempts() + 1);
  logger.debug("initialization attempt " + getInitAttempts());

  // first - get the service information or register service with metadata
  if (getService() != null) {
    // if we were able to get the service data we're registered
    setRegistered(true);
    // second - invoke any custom initialization method
    setInitialized(initialize(getServiceId()));
  }

  // if both are successful, then we're done
  if (isRegistered() && isInitialized()) {
    logger.info("initialization successful.");
  } else {
    // otherwise see if we need to keep going
    if ((getInitRetries() == 0) || (getInitAttempts() < getInitRetries())) {
      logger.debug("initialization unsuccessful. sleeping " + getInitInterval());
      try {
        Thread.sleep(getInitInterval());
      } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
      }
      // start up the next thread
      attemptToInitialize();

    } else {
      // here, we've failed and run out of retries, so just be done.
      logger.info(
          "initialization unsuccessful after " + getInitAttempts() + " attempts.  Giving up.");
      // TODO: what do we do here? exit?
      Application.exit(-1);
    }
  }
}
ProfileEventProducer.java 文件源码 项目:xm-ms-entity 阅读 24 收藏 0 点赞 0 评论 0
/**
 * Send event to kafka.
 * @param content the event data
 */
@Async
public void send(String content) {
    if (StringUtils.isNoneBlank(content)) {
        log.debug("Sending kafka event with data {} to topic {}", content, topicName);
        template.send(topicName, content);
    }
}
MailService.java 文件源码 项目:speakTogether 阅读 28 收藏 0 点赞 0 评论 0
@Async
public void sendActivationEmail(User user) {
    log.debug("Sending activation e-mail to '{}'", user.getEmail());
    Locale locale = Locale.forLanguageTag(user.getLangKey());
    Context context = new Context(locale);
    context.setVariable(USER, user);
    context.setVariable(BASE_URL, jHipsterProperties.getMail().getBaseUrl());
    String content = templateEngine.process("activationEmail", context);
    String subject = messageSource.getMessage("email.activation.title", null, locale);
    sendEmail(user.getEmail(), subject, content, false, true);
}
MailService.java 文件源码 项目:Code4Health-Platform 阅读 34 收藏 0 点赞 0 评论 0
@Async
public void sendActivationEmail(User user) {
    log.debug("Sending activation e-mail to '{}'", user.getEmail());
    Locale locale = Locale.forLanguageTag(user.getLangKey());
    Context context = new Context(locale);
    context.setVariable(USER, user);
    context.setVariable(BASE_URL, jHipsterProperties.getMail().getBaseUrl());
    String content = templateEngine.process("activationEmail", context);
    String subject = messageSource.getMessage("email.activation.title", null, locale);
    sendEmail(user.getEmail(), subject, content, false, true);
}


问题


面经


文章

微信
公众号

扫码关注公众号