管理功能
管理功能我目前写在了com.funtester.base.constaint.FunThread类中,通过一个java.util.Vector集合存放所有的运行任务,当做一个任务池,增加了添加、删除、查询、终止、克隆的方法。
动态执行类
执行类由于不需要统计数据了,只需要进行任务池管理即可,所以显得非常简单。
package com.funtester.frame.execute;import com.funtester.base.constaint.FunThread;import com.funtester.base.interfaces.IFunController;import com.funtester.config.HttpClientConstant;import com.funtester.frame.SourceCode;import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;import java.util.ArrayList;import java.util.List;import java.util.concurrent.ExecutorService;/** * 动态压测模型的启动类 */public class FunConcurrent extends SourceCode { private static Logger logger = LogManager.getLogger(FunConcurrent.class); /*** 任务集*/ public ListFunThread> threads = new ArrayList>(); /*** 线程池*/ public static ExecutorService executorService; public static IFunController controller; /*** @param threads 线程组*/ public FunConcurrent(ListFunThread> threads) {this.threads = threads;executorService = ThreadPoolUtil.createCachePool(HttpClientConstant.THREADPOOL_MAX); } private FunConcurrent() { } /*** 执行多线程任务* 默认取list中thread对象,丢入线程池,完成多线程执行,如果没有threadname,name默认采用desc+线程数作为threadname,去除末尾的日期*/ public void start() {if (controller == null) controller = new FunTester();new Thread(controller,"接收器").start();threads.forEach(f -> addTask(f)); } public static void addTask(FunThread thread) {boolean b = FunThread.addThread(thread);logger.info("任务{}添加{}", thread.threadName, b /span> "成功" : "失败");声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!