Class 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,
cn1.task.executor.<name>.kind (platform or virtual),
cn1.task.executor.<name>.queue-capacity (how many tasks may wait for a
pool thread before TaskRejectedException; unbounded by default) and
cn1.task.executor.<name>.thread-name-prefix,
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.
-
Method Summary
Modifier and TypeMethodDescriptionvoidRunstaskon this executor.intTasks running now.longlongTasks the shutdown deadline dropped before they could start.longTasks that ended with an exception nobody received.getName()intTasks waiting for a thread.intgetSize()booleanWhethershutdown(long)has been called; it then refuses tasks.booleanWhether 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.voidsetTaskDecorator(TaskDecorator decorator) Wraps every task submitted from now on; null removes the decorator.voidshutdown(long waitMillis) Stops taking tasks and waits up towaitMillisfor the queued and running ones to finish.toString()Returns a string representation of the object.
-
Method Details
-
setTaskDecorator
Wraps every task submitted from now on; null removes the decorator. Tasks already submitted run as they were.- Parameters:
decorator- the decorator, or null
-
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
Runs
taskon this executor.Throws
IllegalStateException: once the server has stopped it
-
isShutdown
public boolean isShutdown()Whethershutdown(long)has been called; it then refuses tasks. -
shutdown
public void shutdown(long waitMillis) Stops taking tasks and waits up to
waitMillisfor 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
Description copied from class:ObjectReturns 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())
-