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

x33g5p2x  于2022-01-29 转载在 其他  
字(12.7k)|赞(0)|评价(0)|浏览(449)

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

TaskScheduler介绍

[英]Task scheduler interface that abstracts the scheduling of Runnable based on different kinds of triggers.

This interface is separate from SchedulingTaskExecutor since it usually represents for a different kind of backend, i.e. a thread pool with different characteristics and capabilities. Implementations may implement both interfaces if they can handle both kinds of execution characteristics.

The 'default' implementation is org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler, wrapping a native java.util.concurrent.ScheduledExecutorServiceand adding extended trigger capabilities.

This interface is roughly equivalent to a JSR-236 ManagedScheduledExecutorService as supported in Java EE 7 environments but aligned with Spring's TaskExecutor model.
[中]任务调度器接口,根据不同类型的触发器抽象Runnable的调度。
此接口与SchedulingTaskExecutor不同,因为它通常表示不同类型的后端,即具有不同特征和功能的线程池。如果实现可以处理这两种执行特征,则可以实现这两种接口。
“默认”实现是org。springframework。行程安排。同时发生的ThreadPoolTaskScheduler,包装本机java。util。同时发生的ScheduledExecutorService并添加扩展触发器功能。
该接口大致相当于Java EE 7环境中支持的JSR-236 ManagedScheduledExecutor服务,但与Spring的TaskExecutor模型保持一致。

代码示例

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

@Override
public ScheduledFuture<?> schedule(Runnable task, Date startTime) {
  return taskScheduler.schedule(task, startTime);
}

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

@Override
public ScheduledFuture<?> scheduleAtFixedRate(Runnable task, long period) {
  return taskScheduler.scheduleAtFixedRate(task, period);
}

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

@Override
  public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, long delay) {
    return taskScheduler.scheduleWithFixedDelay(task, delay);
  }
}

代码示例来源:origin: liuht777/Taroco

public void initInterval() {
  taskScheduler.scheduleAtFixedRate(() -> {
    // 刷新apps
    registryApps();
    Collection<Application> apps = applicationStore.findAll();
    // 循环刷新app 状态
    for (Application app : apps) {
      taskScheduler.schedule(new AppRefresh(app, restTemplate), new Date());
    }
  }, serverProperties.getMonitor().getStatusRefreshIntervalInMills());
}

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

/**
 * Schedule the given {@link Runnable}, invoking it at the specified execution time.
 * <p>Execution will end once the scheduler shuts down or the returned
 * {@link ScheduledFuture} gets cancelled.
 * @param task the Runnable to execute whenever the trigger fires
 * @param startTime the desired execution time for the task
 * (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
 * @return a {@link ScheduledFuture} representing pending completion of the task
 * @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
 * for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
 * @since 5.0
 * @see #schedule(Runnable, Date)
 */
default ScheduledFuture<?> schedule(Runnable task, Instant startTime) {
  return schedule(task, Date.from(startTime));
}

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

/**
 * Schedule the given {@link Runnable}, starting as soon as possible and
 * invoking it with the given period.
 * <p>Execution will end once the scheduler shuts down or the returned
 * {@link ScheduledFuture} gets cancelled.
 * @param task the Runnable to execute whenever the trigger fires
 * @param period the interval between successive executions of the task
 * @return a {@link ScheduledFuture} representing pending completion of the task
 * @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
 * for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
 * @since 5.0
 * @see #scheduleAtFixedRate(Runnable, long)
 */
default ScheduledFuture<?> scheduleAtFixedRate(Runnable task, Duration period) {
  return scheduleAtFixedRate(task, period.toMillis());
}

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

/**
 * Schedule the given {@link Runnable}, starting as soon as possible and invoking it with
 * the given delay between the completion of one execution and the start of the next.
 * <p>Execution will end once the scheduler shuts down or the returned
 * {@link ScheduledFuture} gets cancelled.
 * @param task the Runnable to execute whenever the trigger fires
 * @param delay the delay between the completion of one execution and the start of the next
 * @return a {@link ScheduledFuture} representing pending completion of the task
 * @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
 * for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
 * @since 5.0
 * @see #scheduleWithFixedDelay(Runnable, long)
 */
default ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, Duration delay) {
  return scheduleWithFixedDelay(task, delay.toMillis());
}

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

@Override
public ScheduledFuture<?> schedule(Runnable task, Trigger trigger) {
  return taskScheduler.schedule(task, trigger);
}

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

@Override
public ScheduledFuture<?> scheduleAtFixedRate(Runnable task, Date startTime, long period) {
  return taskScheduler.scheduleAtFixedRate(task, startTime, period);
}

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

@Override
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, Date startTime, long delay) {
  return taskScheduler.scheduleWithFixedDelay(task, startTime, delay);
}

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

private void scheduleConnectTimeoutTask(ConnectCallback connectHandler) {
  if (this.timeoutScheduler != null) {
    if (logger.isTraceEnabled()) {
      logger.trace("Scheduling connect to time out after " + this.timeoutValue + " ms.");
    }
    Date timeoutDate = new Date(System.currentTimeMillis() + this.timeoutValue);
    this.timeoutScheduler.schedule(connectHandler, timeoutDate);
  }
  else if (logger.isTraceEnabled()) {
    logger.trace("Connect timeout task not scheduled (no TaskScheduler configured).");
  }
}

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

/**
 * Schedule the given {@link Runnable}, invoking it at the specified execution time
 * and subsequently with the given period.
 * <p>Execution will end once the scheduler shuts down or the returned
 * {@link ScheduledFuture} gets cancelled.
 * @param task the Runnable to execute whenever the trigger fires
 * @param startTime the desired first execution time for the task
 * (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
 * @param period the interval between successive executions of the task
 * @return a {@link ScheduledFuture} representing pending completion of the task
 * @throws org.springframework.core.task.TaskRejectedException if  the given task was not accepted
 * for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
 * @since 5.0
 * @see #scheduleAtFixedRate(Runnable, Date, long)
 */
default ScheduledFuture<?> scheduleAtFixedRate(Runnable task, Instant startTime, Duration period) {
  return scheduleAtFixedRate(task, Date.from(startTime), period.toMillis());
}

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

/**
 * Schedule the given {@link Runnable}, invoking it at the specified execution time
 * and subsequently with the given delay between the completion of one execution
 * and the start of the next.
 * <p>Execution will end once the scheduler shuts down or the returned
 * {@link ScheduledFuture} gets cancelled.
 * @param task the Runnable to execute whenever the trigger fires
 * @param startTime the desired first execution time for the task
 * (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
 * @param delay the delay between the completion of one execution and the start of the next
 * @return a {@link ScheduledFuture} representing pending completion of the task
 * @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
 * for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
 * @since 5.0
 * @see #scheduleWithFixedDelay(Runnable, Date, long)
 */
default ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, Instant startTime, Duration delay) {
  return scheduleWithFixedDelay(task, Date.from(startTime), delay.toMillis());
}

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

/**
 * Schedule the given {@link Runnable}, invoking it at the specified execution time.
 * <p>Execution will end once the scheduler shuts down or the returned
 * {@link ScheduledFuture} gets cancelled.
 * @param task the Runnable to execute whenever the trigger fires
 * @param startTime the desired execution time for the task
 * (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
 * @return a {@link ScheduledFuture} representing pending completion of the task
 * @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
 * for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
 * @since 5.0
 * @see #schedule(Runnable, Date)
 */
default ScheduledFuture<?> schedule(Runnable task, Instant startTime) {
  return schedule(task, Date.from(startTime));
}

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

/**
 * Schedule the given {@link Runnable}, starting as soon as possible and
 * invoking it with the given period.
 * <p>Execution will end once the scheduler shuts down or the returned
 * {@link ScheduledFuture} gets cancelled.
 * @param task the Runnable to execute whenever the trigger fires
 * @param period the interval between successive executions of the task
 * @return a {@link ScheduledFuture} representing pending completion of the task
 * @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
 * for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
 * @since 5.0
 * @see #scheduleAtFixedRate(Runnable, long)
 */
default ScheduledFuture<?> scheduleAtFixedRate(Runnable task, Duration period) {
  return scheduleAtFixedRate(task, period.toMillis());
}

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

/**
 * Schedule the given {@link Runnable}, starting as soon as possible and invoking it with
 * the given delay between the completion of one execution and the start of the next.
 * <p>Execution will end once the scheduler shuts down or the returned
 * {@link ScheduledFuture} gets cancelled.
 * @param task the Runnable to execute whenever the trigger fires
 * @param delay the delay between the completion of one execution and the start of the next
 * @return a {@link ScheduledFuture} representing pending completion of the task
 * @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
 * for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
 * @since 5.0
 * @see #scheduleWithFixedDelay(Runnable, long)
 */
default ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, Duration delay) {
  return scheduleWithFixedDelay(task, delay.toMillis());
}

代码示例来源:origin: Netflix/genie

private synchronized void setDisconnected() {
  this.isConnected = false;
  // Schedule a stream reset
  this.taskScheduler.schedule(
    this::resetStreamTask,
    Instant.ofEpochMilli(System.currentTimeMillis() + STREAM_RESET_DELAY_MILLIS)
  );
}

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

/**
 * Schedule the given {@link Runnable}, invoking it at the specified execution time
 * and subsequently with the given period.
 * <p>Execution will end once the scheduler shuts down or the returned
 * {@link ScheduledFuture} gets cancelled.
 * @param task the Runnable to execute whenever the trigger fires
 * @param startTime the desired first execution time for the task
 * (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
 * @param period the interval between successive executions of the task
 * @return a {@link ScheduledFuture} representing pending completion of the task
 * @throws org.springframework.core.task.TaskRejectedException if  the given task was not accepted
 * for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
 * @since 5.0
 * @see #scheduleAtFixedRate(Runnable, Date, long)
 */
default ScheduledFuture<?> scheduleAtFixedRate(Runnable task, Instant startTime, Duration period) {
  return scheduleAtFixedRate(task, Date.from(startTime), period.toMillis());
}

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

/**
 * Schedule the given {@link Runnable}, invoking it at the specified execution time
 * and subsequently with the given delay between the completion of one execution
 * and the start of the next.
 * <p>Execution will end once the scheduler shuts down or the returned
 * {@link ScheduledFuture} gets cancelled.
 * @param task the Runnable to execute whenever the trigger fires
 * @param startTime the desired first execution time for the task
 * (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
 * @param delay the delay between the completion of one execution and the start of the next
 * @return a {@link ScheduledFuture} representing pending completion of the task
 * @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
 * for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
 * @since 5.0
 * @see #scheduleWithFixedDelay(Runnable, Date, long)
 */
default ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, Instant startTime, Duration delay) {
  return scheduleWithFixedDelay(task, Date.from(startTime), delay.toMillis());
}

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

private void initReceiptHandling() {
  Assert.notNull(getTaskScheduler(), "To track receipts, a TaskScheduler must be configured");
  DefaultStompSession.this.receiptHandlers.put(this.receiptId, this);
  Date startTime = new Date(System.currentTimeMillis() + getReceiptTimeLimit());
  this.future = getTaskScheduler().schedule(this::handleReceiptNotReceived, startTime);
}

相关文章