Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a new thread pool plugin that allows users to actively destroy worker threads (#1208) #1362

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

Createsequence
Copy link
Collaborator

@Createsequence Createsequence commented May 29, 2023

Fixes #1208

Changes proposed in this pull request:

A new plugin

The plugin uses the method of throwing exceptions to let the thread pool actively interrupt (destroy) worker threads without losing tasks.

This plugin extends the ExecuteAwarePlugin interface and is used to check if the number of active threads in the thread pool exceeds the maximum thread count.

Internally, it maintains an overflowThreadNumber variable to represent the number of overflow threads (i.e., activeCount - maximumActiveCount). This variable can be set using setOverflowThreadNumber or updated using checkOverflowThreads based on activeCount - maximumActiveCount.

When the worker in the thread pool executes the beforeExecute method, it checks the overflowThreadNumber. If there are overflow threads, it will atomically decrement the value using CAS, output a warning log, throw an IllegalMaximumActiveCountException exception, and interrupt the worker thread. Finally, it resubmits the task to the current thread pool.

A new plugin registrar

For performance reasons, if the overflowThreadNumber is not explicitly set to a non-zero value, it will not actively check the thread pool.

We also provide a MaximumActiveThreadCountCheckerRegistrar for managing this plugin. In addition to registering the plugin with the thread pool using it, it also supports periodically initiating checks to thread pools registered with this plugin.

@Createsequence Createsequence changed the title add new plugin that checks whether the maximum number of threads in the thread pool is exceeded(#1208) Added a new thread pool plugin that allows users to actively destroy worker threads (#1208) Aug 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] The number of threads in the thread pool decreases in real time
1 participant