多线程实现按钮连续点击

在日常测试中,按钮的连续点击可能会造成应用的奔溃,或者重复提交请求,对此我研究了下如何实现按钮的快速连续点击
思路如下:多线程实现连点并发的效果,每个线程执行adb shell input tap 命令模拟点击

代码如下:
1.cmd命令执行工具类

package utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class CmdUtils {
    ListresultList=new ArrayList();
    public List excuteCmd(String command){
        //String command="adb devices";
        String line = null;
        StringBuilder sb = new StringBuilder();
        Runtime runtime = Runtime.getRuntime();
        try {
            Process process = runtime.exec(command);
            BufferedReader  bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            while ((line = bufferedReader.readLine()) != null) {
                resultList.add(line);
            
            }
        } catch (IOException e) {
            
            e.printStackTrace();
        }
        return resultList;
        
    }


}

2.主类代码

package utils;

public class test002 {
    CmdUtils cmdUtils=new CmdUtils();
    public test002(){
        
        //10个线程执行点击,模拟的点击线程不要超过100,否则对手机会造成损害
        for(int i=0;i<10;i++){
            new AA().start();
        }
        
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        new test002();
    
    }
    //模拟点击线程
    class AA extends Thread{
        @Override
        public void run() {
            // TODO Auto-generated method stub
            super.run();
            cmdUtils.excuteCmd("adb shell input tap 250 700");
            
        }
    }

}

你可能感兴趣的:(多线程实现按钮连续点击)