Top Fields Constructors Methods
org.glassfish.grizzly.threadpool

public Class VirtualThreadExecutorService

extends AbstractExecutorService
implements ThreadPoolInfo, UncaughtExceptionHandler
Class Inheritance
All Implemented Interfaces
java.lang.Thread.UncaughtExceptionHandler, org.glassfish.grizzly.threadpool.ThreadPoolInfo
Imports
org.glassfish.grizzly.Grizzly, org.glassfish.grizzly.localization.LogMessages, java.util.List, .Objects, java.util.concurrent.AbstractExecutorService, .ExecutorService, .Executors, .RejectedExecutionException, .Semaphore, .ThreadFactory, .TimeUnit, java.util.concurrent.atomic.AtomicInteger, java.util.logging.Level, .Logger, org.glassfish.grizzly.monitoring.DefaultMonitoringConfig, .MonitoringUtils

Author
mazhen

Field Summary

Modifier and TypeField and Description
private final ExecutorService
private static final Logger
protected final DefaultMonitoringConfig<ThreadPoolProbe>
monitoringConfig

ThreadPool probes

private final ThreadPoolConfig
private final Semaphore
private final Semaphore
private final AtomicInteger
private final AtomicInteger

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public boolean
awaitTermination(long timeout, TimeUnit unit)

Implements java.util.concurrent.ExecutorService.awaitTermination.

Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.

private void
beforeExecute(final AbstractThreadPool.Worker worker, final Thread t, final Runnable r)

public static VirtualThreadExecutorService
public static VirtualThreadExecutorService
pack-priv Object
public void
execute(Runnable task)

Implements java.util.concurrent.Executor.execute.

Executes the given command at some time in the future.

public ThreadPoolConfig
public DefaultMonitoringConfig<ThreadPoolProbe>
public int
public int
private ThreadFactory
public boolean
public boolean
isTerminated()

Implements java.util.concurrent.ExecutorService.isTerminated.

Returns true if all tasks have completed following shut down.

protected void
onMaxNumberOfThreadsReached()

Method is called by AbstractThreadPool, when maximum number of worker threads is reached and task will need to wait in task queue, until one of the threads will be able to process it.

protected void
onTaskCancelled(Runnable task)

Method is called by a thread pool each time a dequeued task has been canceled instead of being processed.

protected void
onTaskCompletedEvent(Runnable
the unit of work that has completed processing
task
)

This method will be invoked when a the specified Runnable has completed execution.

protected void
onTaskDequeued(Runnable task)

Method is called by a thread pool each time a task has been dequeued from a task queue.

protected void
onTaskQueued(Runnable task)

Method is called by a thread pool each time new task has been queued to a task queue.

protected void
onWorkerExit(Thread thread)

Method is called by Worker, when it's completing Worker#run() method execution, which in most cases means, that ThreadPool's thread will be released.

protected void
onWorkerStarted(Thread thread)

Method is called by Worker, when it's starting Worker#run() method execution, which means, that ThreadPool's thread is getting active and ready to process tasks.

public void
shutdown()

Implements java.util.concurrent.ExecutorService.shutdown.

Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.

public List<Runnable>
shutdownNow()

Implements java.util.concurrent.ExecutorService.shutdownNow.

Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.

public void
uncaughtException(Thread thread, Throwable throwable)

Implements java.lang.Thread.UncaughtExceptionHandler.uncaughtException.

Method invoked when the given thread terminates due to the given uncaught exception.

Inherited from java.util.concurrent.AbstractExecutorService:
invokeAllinvokeAllinvokeAnyinvokeAnynewTaskFornewTaskForsubmitsubmitsubmit

Field Detail

internalExecutorServiceback to summary
private final ExecutorService internalExecutorService
loggerback to summary
private static final Logger logger
monitoringConfigback to summary
protected final DefaultMonitoringConfig<ThreadPoolProbe> monitoringConfig

ThreadPool probes

originalConfigback to summary
private final ThreadPoolConfig originalConfig
poolSemaphoreback to summary
private final Semaphore poolSemaphore
queueSemaphoreback to summary
private final Semaphore queueSemaphore
queueSizeback to summary
private final AtomicInteger queueSize
threadsCountback to summary
private final AtomicInteger threadsCount

Constructor Detail

VirtualThreadExecutorServiceback to summary
protected VirtualThreadExecutorService(ThreadPoolConfig config)

Method Detail

awaitTerminationback to summary
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException

Implements java.util.concurrent.ExecutorService.awaitTermination.

Doc from java.util.concurrent.ExecutorService.awaitTermination.

Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.

Annotations
@Override
Exceptions
InterruptedException:
if interrupted while waiting
beforeExecuteback to summary
private void beforeExecute(final AbstractThreadPool.Worker worker, final Thread t, final Runnable r)
createInstanceback to summary
public static VirtualThreadExecutorService createInstance()
createInstanceback to summary
public static VirtualThreadExecutorService createInstance(ThreadPoolConfig cfg)
createJmxManagementObjectback to summary
pack-priv Object createJmxManagementObject()
executeback to summary
public void execute(Runnable task)

Implements java.util.concurrent.Executor.execute.

Doc from java.util.concurrent.Executor.execute.

Executes the given command at some time in the future. The command may execute in a new thread, in a pooled thread, or in the calling thread, at the discretion of the Executor implementation.

Annotations
@Override
getConfigback to summary
public ThreadPoolConfig getConfig()

Implements org.glassfish.grizzly.threadpool.ThreadPoolInfo.getConfig.

Annotations
@Override
getMonitoringConfigback to summary
public DefaultMonitoringConfig<ThreadPoolProbe> getMonitoringConfig()

Implements org.glassfish.grizzly.threadpool.ThreadPoolInfo.getMonitoringConfig.

Annotations
@Override
getQueueSizeback to summary
public int getQueueSize()

Implements org.glassfish.grizzly.threadpool.ThreadPoolInfo.getQueueSize.

Annotations
@Override
getSizeback to summary
public int getSize()

Implements org.glassfish.grizzly.threadpool.ThreadPoolInfo.getSize.

Annotations
@Override
getThreadFactoryback to summary
private ThreadFactory getThreadFactory(ThreadPoolConfig threadPoolConfig)
isShutdownback to summary
public boolean isShutdown()

Implements org.glassfish.grizzly.threadpool.ThreadPoolInfo.isShutdown, java.util.concurrent.ExecutorService.isShutdown.

Doc from java.util.concurrent.ExecutorService.isShutdown.

Returns true if this executor has been shut down.

Annotations
@Override
isTerminatedback to summary
public boolean isTerminated()

Implements java.util.concurrent.ExecutorService.isTerminated.

Doc from java.util.concurrent.ExecutorService.isTerminated.

Returns true if all tasks have completed following shut down. Note that isTerminated is never true unless either shutdown or shutdownNow was called first.

Annotations
@Override
onMaxNumberOfThreadsReachedback to summary
protected void onMaxNumberOfThreadsReached()

Method is called by AbstractThreadPool, when maximum number of worker threads is reached and task will need to wait in task queue, until one of the threads will be able to process it.

onTaskCancelledback to summary
protected void onTaskCancelled(Runnable task)

Method is called by a thread pool each time a dequeued task has been canceled instead of being processed.

onTaskCompletedEventback to summary
protected void onTaskCompletedEvent(Runnable task)

This method will be invoked when a the specified Runnable has completed execution.

Parameters
task:Runnable

the unit of work that has completed processing

onTaskDequeuedback to summary
protected void onTaskDequeued(Runnable task)

Method is called by a thread pool each time a task has been dequeued from a task queue.

onTaskQueuedback to summary
protected void onTaskQueued(Runnable task)

Method is called by a thread pool each time new task has been queued to a task queue.

onWorkerExitback to summary
protected void onWorkerExit(Thread thread)

Method is called by Worker, when it's completing Worker#run() method execution, which in most cases means, that ThreadPool's thread will be released. This method is called from Worker's thread.

onWorkerStartedback to summary
protected void onWorkerStarted(Thread thread)

Method is called by Worker, when it's starting Worker#run() method execution, which means, that ThreadPool's thread is getting active and ready to process tasks. This method is called from Worker's thread.

shutdownback to summary
public void shutdown()

Implements java.util.concurrent.ExecutorService.shutdown.

Doc from java.util.concurrent.ExecutorService.shutdown.

Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. Invocation has no additional effect if already shut down.

This method does not wait for previously submitted tasks to complete execution. Use awaitTermination to do that.

Annotations
@Override
shutdownNowback to summary
public List<Runnable> shutdownNow()

Implements java.util.concurrent.ExecutorService.shutdownNow.

Doc from java.util.concurrent.ExecutorService.shutdownNow.

Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.

This method does not wait for actively executing tasks to terminate. Use awaitTermination to do that.

There are no guarantees beyond best-effort attempts to stop processing actively executing tasks. For example, typical implementations will cancel via Thread#interrupt, so any task that fails to respond to interrupts may never terminate.

Annotations
@Override
uncaughtExceptionback to summary
public void uncaughtException(Thread thread, Throwable throwable)

Implements java.lang.Thread.UncaughtExceptionHandler.uncaughtException.

Doc from java.lang.Thread.UncaughtExceptionHandler.uncaughtException.

Method invoked when the given thread terminates due to the given uncaught exception.

Any exception thrown by this method will be ignored by the Java Virtual Machine.

Annotations
@Override