How to loop a service?

前端 未结 5 1206
深忆病人
深忆病人 2021-02-05 11:53

My service needs to check for something every minute and

while(true)
{
   Thread.sleep(60000) 
   //REST OF CODE HERE//
}

is not working. Makin

5条回答
  •  滥情空心
    2021-02-05 12:40

    create a thread in your service and put while loop there like this:

     new Thread(new Runnable(){
        public void run() {
        // TODO Auto-generated method stub
        while(true)
        {
           Thread.sleep(60000) 
           //REST OF CODE HERE//
        }
    
                        }
    }).start();
    

提交回复
热议问题