Skip to content

Queue Type

ZjzMisaka edited this page Sep 3, 2024 · 4 revisions

FIFO | LIFO

By setting the QueueType, you can determine whether the thread pool will operate in a first-in-first-out (FIFO) or last-in-first-out (LIFO) manner to meet various business requirements.
Default is FIFO.

powerPool.PowerPoolOption = new PowerPoolOption()
{
    QueueType = QueueType.LIFO,
};

Custom

If PowerPoolOption.CustomQueueFactory is set, regardless of whether QueueType is set or not, PowerThreadPool will use instances of the custom queue type to manage work items.
The custom queue type must inherit from the IStealablePriorityCollection<string> interface, which includes three methods.

Functions

Sets an item with a specified priority in the collection.

void Set(T item, int priority);

Retrieves and removes the highest priority item from the collection.
The method is typically called by the owner thread to fetch the next work.

T Get();

Steals and removes the lowest priority item from the collection.
This method is typically called by other threads to steal work from the owner thread.

T Steal();