Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

public final class TaskExecutor

  1. Object
  2. TaskExecutor

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

Configured as cn1.task.executor.<name>.threads and cn1.task.executor.<name>.kind (platform or virtual), and listed by Tasks.executors. 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.

Methods

public String getName()
public synchronized 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.
public int getSize()
public synchronized int getQueueDepth()Tasks waiting for a thread.
public synchronized int getActiveCount()Tasks running now.
public synchronized long getCompletedCount()
public synchronized long getFailedCount()Tasks that ended with an exception nobody received.
public void execute(Runnable task)Runs task on this executor.
public synchronized boolean isShutdown()Whether shutdown(long) has been called; it then refuses tasks.
public synchronized void shutdown(long waitMillis)Stops taking tasks and waits up to waitMillis for the queued and running ones to finish.
public synchronized long getDroppedCount()Tasks the shutdown deadline dropped before they could start.
public synchronized String toString()Returns a string representation of the object.

Inherited methods

Method details

getName

public String getName()

isVirtual

public synchronized 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 synchronized int getQueueDepth()
Tasks waiting for a thread.

getActiveCount

public synchronized int getActiveCount()
Tasks running now.

getCompletedCount

public synchronized long getCompletedCount()

getFailedCount

public synchronized 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 synchronized boolean isShutdown()
Whether shutdown(long) has been called; it then refuses tasks.

shutdown

public synchronized 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 synchronized long getDroppedCount()
Tasks the shutdown deadline dropped before they could start.

toString

public synchronized String toString()
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())