Class Tasks

java.lang.Object
com.codename1.backend.Tasks

public final class Tasks extends Object

Where background work runs: the named TaskExecutors, and two shorthands for running something once.

  Tasks.platform(new Runnable() { public void run() { rebuildIndex(); } });
  Tasks.virtual(new Runnable() { public void run() { pingWebhooks(); } });

Whose executors

Every server has its own executors, sized from its own configuration and stopped with it: two servers in one process -- or one stopped and started again -- must not share a pool, or stopping one would shut down the executor the other's scheduler and @Async methods still submit to. The calls here are static because generated code makes them, so they find the server by the calling thread: a request thread, a task thread and a scheduled job all carry the server they work for, and so does the thread that builds and starts the beans. A thread that carries none -- one the program started itself -- gets the most recently started server that is still running.

Which thread

A virtual thread is the cheaper one, and the right one for work that waits on sockets -- a PostgreSQL or MySQL query or an HTTP call parks it. It is the wrong one for SQLite or file work: those block the HOST thread under the virtual thread, and every other virtual thread on that host with it. See com.codename1.backend.annotations.ThreadKind.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
    static final String
    The executor @Async methods use when they name none.
    static final int
     
    static final String
    The executor scheduled jobs use when they name none.
    static final int
     
  • Method Summary

    Modifier and Type
    Method
    Description
    executor(String name, int kind)
    The executor called name of the calling thread's server, created on first use.
    static List
    The executors of every running server, for a listing.
    static List
    The executors of the servers in servers only -- what a metric of the measured servers reads.
    static void
    Runs task once on the default pool of platform threads.
    static void
    shutdown(long waitMillis)
    Stops the executors of the calling thread's server, waiting up to waitMillis in total for what is running.
    static void
    Runs task once on a virtual thread, or a platform one where there are none.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • executor

      public static TaskExecutor executor(String name, int kind)

      The executor called name of the calling thread's server, created on first use.

      Parameters
      • kind: @param kind AUTO, VIRTUAL or PLATFORM: what the code asked for, which cn1.task.executor..kind overrides
    • virtual

      public static void virtual(Runnable task)
      Runs task once on a virtual thread, or a platform one where there are none.
    • platform

      public static void platform(Runnable task)
      Runs task once on the default pool of platform threads.
    • executors

      public static List executors()
      The executors of every running server, for a listing.
    • executorsOf

      public static List executorsOf(Collection servers)
      The executors of the servers in servers only -- what a metric of the measured servers reads. executors() also answers for a server that turned metrics off, whose queues would then appear in another server's telemetry, the one built-in metric counting work from a server that opted out.
    • shutdown

      public static void shutdown(long waitMillis)
      Stops the executors of the calling thread's server, waiting up to waitMillis in total for what is running.