org.springframework.scheduling.annotation.Async类的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(5.9k)|赞(0)|评价(0)|浏览(279)

本文整理了Java中org.springframework.scheduling.annotation.Async类的一些代码示例,展示了Async类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Async类的具体详情如下:
包路径:org.springframework.scheduling.annotation.Async
类名称:Async

Async介绍

暂无

代码示例

Official Spring framework guide

代码示例来源:origin: spring-guides/gs-async-method

@Async
public CompletableFuture<User> findUser(String user) throws InterruptedException {
  logger.info("Looking up " + user);
  String url = String.format("https://api.github.com/users/%s", user);
  User results = restTemplate.getForObject(url, User.class);
  // Artificial delay of 1s for demonstration purposes
  Thread.sleep(1000L);
  return CompletableFuture.completedFuture(results);
}

代码示例来源:origin: spring-projects/spring-data-examples

@Async
  CompletableFuture<List<Customer>> readAllBy();
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Return the qualifier or bean name of the executor to be used when executing the
 * given method, specified via {@link Async#value} at the method or declaring
 * class level. If {@code @Async} is specified at both the method and class level, the
 * method's {@code #value} takes precedence (even if empty string, indicating that
 * the default executor should be used preferentially).
 * @param method the method to inspect for executor qualifier metadata
 * @return the qualifier if specified, otherwise empty string indicating that the
 * {@linkplain #setExecutor(Executor) default executor} should be used
 * @see #determineAsyncExecutor(Method)
 */
@Override
@Nullable
protected String getExecutorQualifier(Method method) {
  // Maintainer's note: changes made here should also be made in
  // AnnotationAsyncExecutionAspect#getExecutorQualifier
  Async async = AnnotatedElementUtils.findMergedAnnotation(method, Async.class);
  if (async == null) {
    async = AnnotatedElementUtils.findMergedAnnotation(method.getDeclaringClass(), Async.class);
  }
  return (async != null ? async.value() : null);
}

代码示例来源:origin: wuyouzhuguli/FEBS-Shiro

@Async
  void saveLog(ProceedingJoinPoint point, SysLog log) throws JsonProcessingException;
}

代码示例来源:origin: org.springframework/spring-context

/**
 * Return the qualifier or bean name of the executor to be used when executing the
 * given method, specified via {@link Async#value} at the method or declaring
 * class level. If {@code @Async} is specified at both the method and class level, the
 * method's {@code #value} takes precedence (even if empty string, indicating that
 * the default executor should be used preferentially).
 * @param method the method to inspect for executor qualifier metadata
 * @return the qualifier if specified, otherwise empty string indicating that the
 * {@linkplain #setExecutor(Executor) default executor} should be used
 * @see #determineAsyncExecutor(Method)
 */
@Override
@Nullable
protected String getExecutorQualifier(Method method) {
  // Maintainer's note: changes made here should also be made in
  // AnnotationAsyncExecutionAspect#getExecutorQualifier
  Async async = AnnotatedElementUtils.findMergedAnnotation(method, Async.class);
  if (async == null) {
    async = AnnotatedElementUtils.findMergedAnnotation(method.getDeclaringClass(), Async.class);
  }
  return (async != null ? async.value() : null);
}

代码示例来源:origin: spring-projects/spring-framework

@Async
public interface AsyncInterface {
  void doSomething(int i);
  Future<String> returnSomething(int i);
}

代码示例来源:origin: spring-projects/spring-framework

@Async
public static class AsyncClassListener implements ApplicationListener<ApplicationEvent> {
  public AsyncClassListener() {
    listenerConstructed++;
  }
  @Override
  public void onApplicationEvent(ApplicationEvent event) {
    listenerCalled++;
    assertTrue(!Thread.currentThread().getName().equals(originalThreadName));
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Async
  @Override
  public void doIt() {
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Async
public static class AsyncClassBeanWithInterface implements RegularInterface {
  public void doSomething(int i) {
    assertTrue(!Thread.currentThread().getName().equals(originalThreadName));
  }
  public Future<String> returnSomething(int i) {
    assertTrue(!Thread.currentThread().getName().equals(originalThreadName));
    return new AsyncResult<>(Integer.toString(i));
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Async
  @Override
  public void doIt() {
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Async
  void asyncMethod() {
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Async
  public void handleAsync();
}

代码示例来源:origin: spring-projects/spring-framework

@Async
  Future<String> returnSomething(int i);
}

代码示例来源:origin: spring-projects/spring-framework

@Async public void incrementAsync() {
  counter++;
}

代码示例来源:origin: spring-projects/spring-framework

@Async
Future<String> asyncFoo(int id);

代码示例来源:origin: spring-projects/spring-framework

@Async
void work();

代码示例来源:origin: spring-projects/spring-framework

@Async
void test();

代码示例来源:origin: spring-projects/spring-framework

@Async
void doSomething(int i);

代码示例来源:origin: spring-projects/spring-framework

@Async
static class ClassWithAsyncAnnotation {
  int counter;
  public void increment() {
    counter++;
  }
  // Manually check that there is a warning from the 'declare warning' statement in
  // AnnotationAsyncExecutionAspect
  /*
  public int return5() {
    return 5;
  }
  */
  public Future<Integer> incrementReturningAFuture() {
    counter++;
    return new AsyncResult<Integer>(5);
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Async("e0")
public static class AsyncMethodWithQualifierBean {
  public void doNothing(int i) {
    assertTrue(Thread.currentThread().getName().equals(originalThreadName));
  }
  @Async("e1")
  public void doSomething(int i) {
    assertTrue(!Thread.currentThread().getName().equals(originalThreadName));
    assertTrue(Thread.currentThread().getName().startsWith("e1-"));
  }
  @MyAsync
  public Future<String> returnSomething(int i) {
    assertTrue(!Thread.currentThread().getName().equals(originalThreadName));
    assertTrue(Thread.currentThread().getName().startsWith("e2-"));
    return new AsyncResult<>(Integer.toString(i));
  }
  public Future<String> returnSomething2(int i) {
    assertTrue(!Thread.currentThread().getName().equals(originalThreadName));
    assertTrue(Thread.currentThread().getName().startsWith("e0-"));
    return new AsyncResult<>(Integer.toString(i));
  }
}

相关文章