<commit_before>package org.voovan.tools.threadpool;

import org.voovan.tools.TEnv;
import org.voovan.tools.TPerformance;
import org.voovan.tools.log.Logger;

import java.util.TimerTask;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 线程池监控类
 *
 * @author helyho
 *
 * Voovan Framework.
 * WebSite: https://github.com/helyho/Voovan
 * Licence: Apache v2 License
 */
public class ThreadPoolTask extends TimerTask {
	private ThreadPoolExecutor	threadPoolInstance;
	private int					cpuCoreCount;

	public ThreadPoolTask(ThreadPoolExecutor threadPoolInstance) {
		cpuCoreCount = Runtime.getRuntime().availableProcessors();
		this.threadPoolInstance = threadPoolInstance;
	}

	@Override
	public void run() {
		if (threadPoolInstance.isShutdown()) {
			this.cancel();
			System.exit(0);
		}

		String threadPoolInfo = "[PoolInfo]: " + threadPoolInstance.getActiveCount() + "/" + threadPoolInstance.getCorePoolSize() + "/"
				+ threadPoolInstance.getLargestPoolSize()+ "/" + threadPoolInstance.getMaximumPoolSize() + " \t[TaskCount]: "
				+ threadPoolInstance.getCompletedTaskCount() + "/"
				+ threadPoolInstance.getTaskCount() + " \t[QueueSize]: " + threadPoolInstance.getQueue().size() + " \t[PerCoreLoadAvg]: "
				+ TPerformance.cpuPerCoreLoadAvg();
		if (threadPoolInstance.getActiveCount() != 0) {
			Logger.fremawork("[ShutDown]: " + threadPoolInstance.isShutdown() + " \t" + threadPoolInfo);
		}

		int poolSize = threadPoolInstance.getPoolSize();
		// 动态调整线程数,且系统CPU负载值要小于1
		if (threadPoolInstance.getQueue().size() > 0 ) {

			int newPoolSize = (int)(threadPoolInstance.getCorePoolSize() * 1.20);

			if(newPoolSize > ThreadPool.MAX_POOL_SIZE){
				newPoolSize = ThreadPool.MAX_POOL_SIZE;
			}

			if(newPoolSize!=poolSize) {
				threadPoolInstance.setCorePoolSize(newPoolSize);
				Logger.fremawork("PoolSizeChange: " + poolSize + "->" + threadPoolInstance.getCorePoolSize());
			}
		}

		else if(threadPoolInstance.getActiveCount() <= threadPoolInstance.getPoolSize()/2 &&
				threadPoolInstance.getCorePoolSize() > ThreadPool.MIN_POOL_SIZE){

			int newPoolsize = (int)(threadPoolInstance.getCorePoolSize()*0.8);

			if(newPoolsize < ThreadPool.MIN_POOL_SIZE){
				newPoolsize = ThreadPool.MIN_POOL_SIZE;
			}

			if(newPoolsize != poolSize) {
				threadPoolInstance.setCorePoolSize(newPoolsize);
				Logger.fremawork("PoolSizeChange: " + poolSize + "->" + threadPoolInstance.getCorePoolSize());
			}
		}

		//如果主线程结束,则线程池也关闭
		if( TEnv.isMainThreadShutDown()) {
			threadPoolInstance.shutdown();
		}
	}
}<commit_msg>fix: 修复线程监视任务失败的问题<commit_after>package org.voovan.tools.threadpool;

import org.voovan.tools.TEnv;
import org.voovan.tools.TPerformance;
import org.voovan.tools.log.Logger;

import java.util.TimerTask;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 线程池监控类
 *
 * @author helyho
 *
 * Voovan Framework.
 * WebSite: https://github.com/helyho/Voovan
 * Licence: Apache v2 License
 */
public class ThreadPoolTask extends TimerTask {
	private ThreadPoolExecutor	threadPoolInstance;
	private int					cpuCoreCount;

	public ThreadPoolTask(ThreadPoolExecutor threadPoolInstance) {
		cpuCoreCount = Runtime.getRuntime().availableProcessors();
		this.threadPoolInstance = threadPoolInstance;
	}

	@Override
	public void run() {
		try {
			if (threadPoolInstance.isShutdown()) {
				this.cancel();
				System.exit(0);
			}

			String threadPoolInfo = "[PoolInfo]: " + threadPoolInstance.getActiveCount() + "/" + threadPoolInstance.getCorePoolSize() + "/"
					+ threadPoolInstance.getLargestPoolSize() + "/" + threadPoolInstance.getMaximumPoolSize() + " \t[TaskCount]: "
					+ threadPoolInstance.getCompletedTaskCount() + "/"
					+ threadPoolInstance.getTaskCount() + " \t[QueueSize]: " + threadPoolInstance.getQueue().size() + " \t[PerCoreLoadAvg]: "
					+ TPerformance.cpuPerCoreLoadAvg();
			if (threadPoolInstance.getActiveCount() != 0) {
				Logger.fremawork("[ShutDown]: " + threadPoolInstance.isShutdown() + " \t" + threadPoolInfo);
			}

			int poolSize = threadPoolInstance.getPoolSize();
			// 动态调整线程数,且系统CPU负载值要小于1
			if (threadPoolInstance.getQueue().size() > 0) {

				int newPoolSize = (int) (threadPoolInstance.getCorePoolSize() * 1.20);

				if (newPoolSize > ThreadPool.MAX_POOL_SIZE) {
					newPoolSize = ThreadPool.MAX_POOL_SIZE;
				}

				if (newPoolSize != poolSize) {
					threadPoolInstance.setCorePoolSize(newPoolSize);
					Logger.fremawork("PoolSizeChange: " + poolSize + "->" + threadPoolInstance.getCorePoolSize());
				}
			} else if (threadPoolInstance.getActiveCount() <= threadPoolInstance.getPoolSize() / 2 &&
					threadPoolInstance.getCorePoolSize() > ThreadPool.MIN_POOL_SIZE) {

				int newPoolsize = (int) (threadPoolInstance.getCorePoolSize() * 0.8);

				if (newPoolsize < ThreadPool.MIN_POOL_SIZE) {
					newPoolsize = ThreadPool.MIN_POOL_SIZE;
				}

				if (newPoolsize != poolSize) {
					threadPoolInstance.setCorePoolSize(newPoolsize);
					Logger.fremawork("PoolSizeChange: " + poolSize + "->" + threadPoolInstance.getCorePoolSize());
				}
			}

			//如果主线程结束,则线程池也关闭
			if (TEnv.isMainThreadShutDown()) {
				threadPoolInstance.shutdown();
			}
		} catch (Exception e){
			Logger.error("Threadpooltask error: ", e);
		}
	}
}
{'fraction_non_alphanumeric': 0.1338068727202918, 'fraction_numerical': 0.0042234593971971586, 'mean_word_length': 4.530785562632697, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5452228', 'n_tokens_mistral': 1983, 'n_tokens_neox': 1778, 'n_words': 242}