建立一個每隔10秒執行的線程


//線程類
public  class  TestThread  extends  Thread {
     public  void  run() {
         while ( true ){
             try  {
                 sleep( 6 * 1000 );
                                 //這里可以寫你自己要運行的邏輯代碼
                 System.out.println( "一分鍾運行一次" );
             catch  (InterruptedException e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
             }
             
         }
     }
}
//運行線程類MAIN
public  class  TestThreadMain {
 
     /**
      * @param args
      */
     public  static  void  main(String[] args) {
         // TODO Auto-generated method stub
         TestThread testThread =  new  TestThread();
         testThread.start();
     }
 
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM