How to use scheduleAtFixedRate for executing in each second

前端 未结 3 1939
南旧
南旧 2020-12-22 09:46

in the below code send() function is executing many times in a second,i want to execute send() once in a second,how i change the code

timer.scheduleAtFixedRa         


        
3条回答
  •  一向
    一向 (楼主)
    2020-12-22 10:14

    an easier approach would look like this:

    new Thread() {
      public void run() {
         while(true) {
           send();
           try{
             Thread.sleep(1000); // pauses for 1 second
           catch(Exception e) {}
         }
      }
    }.start();
    

提交回复
热议问题