类 DefaultUniExecutor

java.lang.Object
cn.wjybxx.sequential.AbstractUniExecutor
cn.wjybxx.sequential.DefaultUniExecutor
所有已实现的接口:
IExecutor, IExecutorService, UniExecutorService, AutoCloseable, Executor, ExecutorService

public class DefaultUniExecutor extends AbstractUniExecutor
默认的executor实现,通过限制每帧执行的任务数来平滑开销
作者:
wjybxx date 2023/4/3
  • 构造器详细资料

    • DefaultUniExecutor

      public DefaultUniExecutor()
    • DefaultUniExecutor

      public DefaultUniExecutor(int countLimit)
    • DefaultUniExecutor

      public DefaultUniExecutor(int countLimit, long timeLimit, TimeUnit timeUnit)
      参数:
      countLimit - 每帧允许运行的最大任务数,-1表示不限制;不可以为0
      timeLimit - 每帧允许的最大时间,-1表示不限制;不可以为0
  • 方法详细资料

    • update

      public void update()
      从接口复制的说明: UniExecutorService
      心跳方法 外部需要每一帧调用该方法以执行任务。
    • needMoreUpdate

      public boolean needMoreUpdate()
      从接口复制的说明: UniExecutorService
      是否需要更多的Update。

      为避免死循环或占用过多cpu,单次UniExecutorService.update()可能存在一些限制,因此可能未执行所有的可执行任务。 该方法用于探测是否还有可执行的任务,如果外部可以分配更多的资源。

      返回:
      如果还有可执行任务则返回true,否则返回false
    • execute

      public void execute(Runnable command)
      从接口复制的说明: IExecutor
      在将来的某个时间执行给定的命令。 命令可以在新线程中执行,也可以在池线程中执行,或者在调用线程中执行,这由Executor实现决定。 Executor.execute(Runnable)
      指定者:
      execute 在接口中 Executor
      指定者:
      execute 在接口中 IExecutor
      指定者:
      execute 在类中 AbstractUniExecutor
      参数:
      command - 要执行的任务,注意ITask类型
    • shutdown

      public void shutdown()
      从接口复制的说明: IExecutorService
      请求关闭 ExecutorService,不再接收新的任务。 ExecutorService在执行完现有任务后,进入关闭状态。 如果 ExecutorService 正在关闭,或已经关闭,则方法不产生任何效果。

      该方法会立即返回,如果想等待 ExecutorService 进入终止状态, 可以使用IExecutorService.awaitTermination(long, TimeUnit)IExecutorService.terminationFuture() 进行等待

    • shutdownNow

      @Nonnull public List<Runnable> shutdownNow()
      从接口复制的说明: IExecutorService
      JDK文档: 请求关闭 ExecutorService,尝试取消所有正在执行的任务,停止所有待执行的任务,并不再接收新的任务。 如果 ExecutorService 已经关闭,则方法不产生任何效果。

      该方法会立即返回,如果想等待 ExecutorService 进入终止状态,可以使用IExecutorService.awaitTermination(long, TimeUnit)IExecutorService.terminationFuture() 进行等待。

      返回:
      被取消的任务
    • isShuttingDown

      public boolean isShuttingDown()
      从接口复制的说明: IExecutorService
      查询EventLoopGroup是否处于正在关闭状态。 正在关闭状态下,拒绝接收新任务,当执行完所有任务后,进入关闭状态。
      返回:
      如果该EventLoopGroup管理的所有EventLoop正在关闭或已关闭则返回true
    • isShutdown

      public boolean isShutdown()
      从接口复制的说明: IExecutorService
      查询EventLoopGroup是否处于关闭状态。 关闭状态下,拒绝接收新任务,执行退出前的清理操作,执行完清理操作后,进入终止状态。
      返回:
      如果已关闭,则返回true
    • isTerminated

      public boolean isTerminated()
      从接口复制的说明: IExecutorService
      是否已进入终止状态,一旦进入终止状态,表示生命周期真正结束。
      返回:
      如果已处于终止状态,则返回true
    • terminationFuture

      public IFuture<?> terminationFuture()
      从接口复制的说明: IExecutorService
      返回Future将在Executor终止时进入完成状态。 1. 返回Future应当是只读的,IFuture.asReadonly() 2. 用户可以在该Future上等待。