Class TaskExecutor

java.lang.Object
com.codename1.backend.TaskExecutor

public final class TaskExecutor extends Object

A named place background work runs: a pool of platform threads, or virtual threads on the server's hosts.

Configured as cn1.task.executor..threads and cn1.task.executor..kind (platform or virtual), and obtained through Tasks.executor(String, int). The threads of a pool start on the first task, so an executor the configuration names and nothing uses costs a map entry.

A virtual executor hands each task to a virtual thread of its own; on a runtime or a server that has none -- the Java SE arm, a TLS server, Windows -- it runs the task on its pool instead, which is why it has a size too.

  • Method Details

    • getName

      public String getName()
    • isVirtual

      public boolean isVirtual()
      Whether this executor's tasks go to virtual threads: always for a virtual one, and for an AUTO one while its server has hosts to run them on.
    • getSize

      public int getSize()
    • getQueueDepth

      public int getQueueDepth()
      Tasks waiting for a thread.
    • getActiveCount

      public int getActiveCount()
      Tasks running now.
    • getCompletedCount

      public long getCompletedCount()
    • getFailedCount

      public long getFailedCount()
      Tasks that ended with an exception nobody received.
    • execute

      public void execute(Runnable task)

      Runs task on this executor.

      Throws
      • IllegalStateException: once the server has stopped it
    • isShutdown

      public boolean isShutdown()
      Whether shutdown(long) has been called; it then refuses tasks.
    • shutdown

      public void shutdown(long waitMillis)

      Stops taking tasks and waits up to waitMillis for the queued and running ones to finish.

      Called from one of this executor's own tasks -- one that stops the server -- that task is not waited for: it cannot finish until this returns. The HTTP drain leaves out the request that stopped it the same way.

    • getDroppedCount

      public long getDroppedCount()
      Tasks the shutdown deadline dropped before they could start.
    • toString

      public String toString()
      Description copied from class: Object
      Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode())
      Overrides:
      toString in class Object