zoukankan      html  css  js  c++  java
  • 阻止在极短的时间重复执行某个函数

    /**
     * 阻止在极短的时间重复执行某个函数中的代码
     * @author wanlh
     *
     */
    public class ReEventsController {
        
        private boolean isRepeatFlag = false;
        private MyRunnable mMyRunnable;
        
        private class MyRunnable implements Runnable{
    
            @Override
            public void run() {
                // TODO Auto-generated method stub
                isRepeatFlag = false;
            }
        }
        
        /**
         * 在time时间之内是否重复,阻止代码往下执行
         * @param view
         * @param time
         * @return
         */
        public boolean isRepeat(View view, int time){
            if(mMyRunnable == null)
                mMyRunnable = new MyRunnable();
            if(isRepeatFlag){
                //view.removeCallbacks(mMyRunnable);
                //view.postDelayed(mMyRunnable, time);//2500毫秒恢复,300毫秒之内不允许重复请求数据
                return true;
            }else{
                isRepeatFlag = true;
                view.removeCallbacks(mMyRunnable);
                view.postDelayed(mMyRunnable, time);//2500毫秒恢复,300毫秒之内不允许重复请求数据
            }
            return false;
        }
    }

     view是WebView.

  • 相关阅读:
    Splash wait() 方法
    Splash go() 方法
    Splash 对象方法
    短信接口文档
    WMS开发环境
    Eureka
    pom.xml settings.xml
    Druid
    EAI并发
    重启WMS服务
  • 原文地址:https://www.cnblogs.com/yaowen/p/5563046.html
Copyright © 2011-2022 走看看