opengoofy / hippo4j

📌 异步线程池框架,支持线程池动态变更&监控&报警,无需修改代码轻松引入。Asynchronous thread pool framework, support Thread Pool Dynamic Change & monitoring & Alarm, no need to modify the code easily introduced.
https://hippo4j.cn
Apache License 2.0
5.56k stars 1.17k forks source link

[Feature] The number of threads in the thread pool decreases in real time #1208

Open magestacks opened 1 year ago

magestacks commented 1 year ago

Demand advice

Please answer these questions before submitting them. Thank you.

Is your function request related to the problem?

NO

Describe the function you want

The number of threads in the thread pool decreases in real time.

Suppose the core and maximum number of threads is 3, n tasks have been run, and the current thread of the thread pool is now 3. And now I've adjusted the number of threads to 1, so when I run the task again, after the task has run, I'll start checking the current thread and the maximum maximum thread, and if it's greater than that, I'll interrupt myself.

I want to do this through the current thread pool plug-in.

@Createsequence

Createsequence commented 1 year ago

I will try to complete it

Createsequence commented 1 year ago

I have a brand new idea, this plugin may be directly used to allow users to quickly and actively destroy worker threads, not limited to destroying worker threads that exceed the maximum number of threads (in fact, this is also an active destruction scenario). Simply put, this plugin can satisfy:

When manually/automatically specify a number n according to a certain strategy, if the current number of threads x (which can be the number of worker threads, or just the number of active threads) is greater than n, the plugin will actively and quickly destroy threads by throwing exceptions.

If this idea is feasible, then the subsequent PR will need to be further adjusted.

magestacks commented 1 year ago

The destruction of worker threads should be controlled by allowCoreThreadTimeOut API, Hippo4j I think it is more appropriate to enhance the destruction of non-core threads.