import com.google.gson.JsonObject;import java.util.ArrayList;import java.util.List;public class TestClientPool {protected TestClientRunnable testClientRunnable;protected List<Thread> threadList;protected volatile boolean running;protected volatile boolean init;protected String url;protected RequestMethod method;protected long waitTime;protected JsonObject data;protected List<TestClientRunnable> runnableList ;protected int count;protected long totalTime;protected int failCount;protected long longestTime = 0;protected long shortestTime = 0x7fffffffffffffffL;public TestClientPool(String url, RequestMethod method, long waitTime){this(url, method, waitTime, new JsonObject());}public TestClientPool(String url, RequestMethod method, long waitTime, JsonObject data){this.url = url;this.method = method;this.waitTime = waitTime;this.data = data;running = false;}public boolean init(int threadCount){if (running){return false;}threadList = new ArrayList<>();runnableList = new ArrayList<>();for(int i = 0 ; i < threadCount ; ++i){runnableList.add(new TestClientRunnable(url, method, waitTime, data));threadList.add(new Thread(runnableList.get(i), "WebTesterThread-" + i));}init = true;return true;}public boolean start(){if (running || !init){return false;}count = 0;long wait = waitTime/threadList.size();for(int i = 0 ; i != threadList.size() ; ++i){threadList.get(i).setDaemon(true);threadList.get(i).start();try {Thread.sleep(wait);}catch (InterruptedException e){}}running = true;return true;}public boolean stop(){if (!running || !init){return false;}for(int i = 0 ; i != threadList.size() ; ++i){threadList.get(i).interrupt();count += runnableList.get(i).getCount();failCount += runnableList.get(i).getFailCount();totalTime += runnableList.get(i).getTotalTime();longestTime = runnableList.get(i).getLongestTime() > longestTime ? runnableList.get(i).getLongestTime() : longestTime;shortestTime = runnableList.get(i).getShortestTime() < shortestTime ? runnableList.get(i).getShortestTime() : shortestTime;}threadList = null;running = false;init = false;return true;}public int getCount(){return count;}public int getFailCount(){return failCount;}public long getTotalTime(){return totalTime;}public long getShortestTime() {return shortestTime;}public long getLongestTime() {return longestTime;}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。