Class ThreadPoolConfig

java.lang.Object
org.glassfish.grizzly.threadpool.ThreadPoolConfig

public final class ThreadPoolConfig extends Object
Grizzly thread-pool configuration, which might be used to create and initialize a thread-pool via GrizzlyExecutorService.createInstance(org.glassfish.grizzly.threadpool.ThreadPoolConfig). One can get a default Grizzly ThreadPoolConfig using copy() and customize it according to the application specific requirements. A ThreadPoolConfig object might be customized in a "Builder"-like fashion: ThreadPoolConfig.defaultConfig() .setPoolName("App1Pool") .setCorePoolSize(5) .setMaxPoolSize(10);
Author:
Oleksiy Stashok, gustav trede
  • Field Details

    • poolName

      protected String poolName
    • corePoolSize

      protected int corePoolSize
    • maxPoolSize

      protected int maxPoolSize
    • queue

      protected Queue<Runnable> queue
    • queueLimit

      protected int queueLimit
    • keepAliveTimeMillis

      protected long keepAliveTimeMillis
    • threadFactory

      protected ThreadFactory threadFactory
    • priority

      protected int priority
    • isDaemon

      protected boolean isDaemon
    • mm

      protected MemoryManager mm
    • transactionMonitor

      protected DelayedExecutor transactionMonitor
    • transactionTimeoutMillis

      protected long transactionTimeoutMillis
    • initialClassLoader

      protected ClassLoader initialClassLoader
    • threadPoolMonitoringConfig

      protected final DefaultMonitoringConfig<ThreadPoolProbe> threadPoolMonitoringConfig
      Thread pool probes
  • Method Details

    • defaultConfig

      public static ThreadPoolConfig defaultConfig()
      Create new Grizzly thread-pool configuration instance. The returned ThreadPoolConfig instance will be pre-configured with a default values.
      Returns:
      the Grizzly thread-pool configuration instance.
    • copy

      public ThreadPoolConfig copy()
    • getQueue

      public Queue<Runnable> getQueue()
      Returns:
      the queue
    • setQueue

      public ThreadPoolConfig setQueue(Queue<Runnable> queue)
      Parameters:
      queue - the queue implemenation to use
      Returns:
      the ThreadPoolConfig with the new Queue implementation.
    • getThreadFactory

      public ThreadFactory getThreadFactory()
      Returns ThreadFactory. If ThreadFactory is set - then priority, isDaemon, poolName settings will not be considered when creating new threads.
      Returns:
      the threadFactory
    • setThreadFactory

      public ThreadPoolConfig setThreadFactory(ThreadFactory threadFactory)
      Parameters:
      threadFactory - custom ThreadFactory If ThreadFactory is set - then priority, isDaemon, poolName settings will not be considered when creating new threads.
      Returns:
      the ThreadPoolConfig with the new ThreadFactory
    • getPoolName

      public String getPoolName()
      Returns:
      the poolname
    • setPoolName

      public ThreadPoolConfig setPoolName(String poolname)
      Parameters:
      poolname - the thread pool name.
      Returns:
      the ThreadPoolConfig with the new thread pool name.
    • getPriority

      public int getPriority()
    • setPriority

      public ThreadPoolConfig setPriority(int priority)
    • isDaemon

      public boolean isDaemon()
    • setDaemon

      public ThreadPoolConfig setDaemon(boolean isDaemon)
    • getMaxPoolSize

      public int getMaxPoolSize()
      Returns:
      the maxpoolsize
    • setMaxPoolSize

      public ThreadPoolConfig setMaxPoolSize(int maxPoolSize)
      Parameters:
      maxPoolSize - the max thread pool size
      Returns:
      the ThreadPoolConfig with the new max pool size
    • getCorePoolSize

      public int getCorePoolSize()
      Returns:
      the corepoolsize
    • setCorePoolSize

      public ThreadPoolConfig setCorePoolSize(int corePoolSize)
      Parameters:
      corePoolSize - the core thread pool size
      Returns:
      the ThreadPoolConfig with the new core pool size
    • getQueueLimit

      public int getQueueLimit()
      Returns:
      the thread-pool queue limit. The queue limit value less than 0 means unlimited queue.
    • setQueueLimit

      public ThreadPoolConfig setQueueLimit(int queueLimit)
      Parameters:
      queueLimit - the thread-pool queue limit. The queueLimit value less than 0 means unlimited queue.
      Returns:
      the ThreadPoolConfig with the new queue limite
    • setKeepAliveTime

      public ThreadPoolConfig setKeepAliveTime(long time, TimeUnit unit)
      The max period of time a thread will wait for a new task to process. If the timeout expires and the thread is not a core one (see setCorePoolSize(int), setMaxPoolSize(int)) - then the thread will be terminated and removed from the thread pool.
      Parameters:
      time - max keep alive timeout. The value less than 0 means no timeout
      unit - time unit
      Returns:
      the ThreadPoolConfig with the new keep alive time
    • getKeepAliveTime

      public long getKeepAliveTime(TimeUnit timeUnit)
      Returns the max period of time a thread will wait for a new task to process. If the timeout expires and the thread is not a core one (see setCorePoolSize(int), setMaxPoolSize(int)) - then the thread will be terminated and removed from the thread pool.
      Returns:
      the keep-alive timeout, the value less than 0 means no timeout
    • getMemoryManager

      public MemoryManager getMemoryManager()
    • setMemoryManager

      public ThreadPoolConfig setMemoryManager(MemoryManager mm)
    • getInitialMonitoringConfig

      public DefaultMonitoringConfig<ThreadPoolProbe> getInitialMonitoringConfig()
    • getTransactionMonitor

      public DelayedExecutor getTransactionMonitor()
    • setTransactionMonitor

      public ThreadPoolConfig setTransactionMonitor(DelayedExecutor transactionMonitor)
    • getTransactionTimeout

      public long getTransactionTimeout(TimeUnit timeUnit)
    • setTransactionTimeout

      public ThreadPoolConfig setTransactionTimeout(long transactionTimeout, TimeUnit timeunit)
    • setTransactionTimeout

      public ThreadPoolConfig setTransactionTimeout(DelayedExecutor transactionMonitor, long transactionTimeout, TimeUnit timeunit)
    • getInitialClassLoader

      public ClassLoader getInitialClassLoader()
      Returns:
      the classloader (if any) to be initially exposed by threads from this pool.
      Since:
      2.3
    • setInitialClassLoader

      public ThreadPoolConfig setInitialClassLoader(ClassLoader initialClassLoader)
      Specifies the context classloader that will be used by threads in this pool. If not specified, the classloader of the parent thread that initialized the pool will be used.
      Parameters:
      initialClassLoader - the classloader to be exposed by threads of this pool.
      Returns:
      the ThreadPoolConfig
      Since:
      2.3
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object