ThreadPool

Overview

The ThreadPool class represents a pool of threads that can be used to execute tasks asynchronously, process network I/O etc. For example, the SuperHttpClientChannel and SuperTcpClientChannel classes use the ThreadPool class instance to process received server events.

This class is very similar to the System.Threading.ThreadPool class except that the RemObjects.SDK.ThreadPool creates new worker threads immediately when they are needed and there are no idle threads in the pool while the System.Threading.ThreadPool class creates new worker threads with a half second delay interval. This could possibly cause a bottleneck when a large number of incoming server events is received.

See the FAQ question as one of the cases where the ThreadPool class can be used to provide needed functionality.

Location

Implements

 

constructor

Creates a new instance of the ThreadPool class.

 

constructor

 

ThreadPool()

 

Sub New

constructor (Int32, Int32)

Creates a new instance of the ThreadPool class and sets its MaxQueue and MaxThread properties.

 

constructor(maxQueue: Int32; maxThread: Int32)

 

ThreadPool(Int32 maxQueue, Int32 maxThread)

 

Sub New (maxQueue As Int32, maxThread As Int32)

Parameters:

  • maxQueue: Maximum task queue length per worker thread
  • maxThread: Maximum amount of worker threads

constructor (IContainer)

Creates a new instance of the ThreadPool class and adds it to the provided components container.

 

constructor(container: IContainer)

 

ThreadPool(IContainer container)

 

Sub New (container As IContainer)

Parameters:

  • container: Components container

Dispose  protected

Disposes of the current ThreadPool instance.

This method stops all currently running worker threads and removes all enqueued worker items.

 

method Dispose(disposing: Boolean)

 

void Dispose(Boolean disposing)

 

Sub Dispose(disposing As Boolean)

Parameters:

  • disposing: True to release both managed and unmanaged resources and stop all worker threads; false to release only unmanaged resource

MaxQueue

Gets or sets the maximum tasks queue length for each worker thread.

When a new work item is enqueued and the length of the queue is greater than the (MaxThread * MaxQueue) property value, an exception is raised.

The default value is 64.

 

property MaxQueue: Int32 read write;

 

Int32 MaxQueue { get; set; }

 

Property MaxQueue As Int32

MaxThread

Gets or sets the maximum number of threads that can be contained in the pool.

The default value is 16.

 

property MaxThread: Int32 read write;

 

Int32 MaxThread { get; set; }

 

Property MaxThread As Int32

PoolThreads

Gets or sets the suggested number of simultaneously running worker threads.

The ThreadPool instance doesn't spawn new worker threads when a work item is enqueued and there are more than PoolThreads threads currently running, each having not more than 1 work item enqueued.

For example, when there are 4 tasks currently running and 3 other tasks enqueued, a new thread would not be spawned when one more worker item is enqueued.

This allows to reduce resources and CPU time consumption.

The default value is 5.

 

property PoolThreads: Int32 read write;

 

Int32 PoolThreads { get; set; }

 

Property PoolThreads As Int32

QueueItem

Enqueues the provided callback method for execution.

 

method QueueItem(callback: ThreadPoolCallback)

 

void QueueItem(ThreadPoolCallback callback)

 

Sub QueueItem(callback As ThreadPoolCallback)

Parameters:

  • callback: ThreadPoolCallback that represents the method to be executed

 

MaxQueue

Gets or sets the maximum tasks queue length for each worker thread.

When a new work item is enqueued and the length of the queue is greater than the (MaxThread * MaxQueue) property value, an exception is raised.

The default value is 64.

 

property MaxQueue: Int32 read write;

 

Int32 MaxQueue { get; set; }

 

Property MaxQueue As Int32

MaxThread

Gets or sets the maximum number of threads that can be contained in the pool.

The default value is 16.

 

property MaxThread: Int32 read write;

 

Int32 MaxThread { get; set; }

 

Property MaxThread As Int32

PoolThreads

Gets or sets the suggested number of simultaneously running worker threads.

The ThreadPool instance doesn't spawn new worker threads when a work item is enqueued and there are more than PoolThreads threads currently running, each having not more than 1 work item enqueued.

For example, when there are 4 tasks currently running and 3 other tasks enqueued, a new thread would not be spawned when one more worker item is enqueued.

This allows to reduce resources and CPU time consumption.

The default value is 5.

 

property PoolThreads: Int32 read write;

 

Int32 PoolThreads { get; set; }

 

Property PoolThreads As Int32

 

constructor

Creates a new instance of the ThreadPool class.

 

constructor

 

ThreadPool()

 

Sub New

constructor (Int32, Int32)

Creates a new instance of the ThreadPool class and sets its MaxQueue and MaxThread properties.

 

constructor(maxQueue: Int32; maxThread: Int32)

 

ThreadPool(Int32 maxQueue, Int32 maxThread)

 

Sub New (maxQueue As Int32, maxThread As Int32)

Parameters:

  • maxQueue: Maximum task queue length per worker thread
  • maxThread: Maximum amount of worker threads

constructor (IContainer)

Creates a new instance of the ThreadPool class and adds it to the provided components container.

 

constructor(container: IContainer)

 

ThreadPool(IContainer container)

 

Sub New (container As IContainer)

Parameters:

  • container: Components container

Dispose  protected

Disposes of the current ThreadPool instance.

This method stops all currently running worker threads and removes all enqueued worker items.

 

method Dispose(disposing: Boolean)

 

void Dispose(Boolean disposing)

 

Sub Dispose(disposing As Boolean)

Parameters:

  • disposing: True to release both managed and unmanaged resources and stop all worker threads; false to release only unmanaged resource

QueueItem

Enqueues the provided callback method for execution.

 

method QueueItem(callback: ThreadPoolCallback)

 

void QueueItem(ThreadPoolCallback callback)

 

Sub QueueItem(callback As ThreadPoolCallback)

Parameters:

  • callback: ThreadPoolCallback that represents the method to be executed

See Also