How to make a thread sleep for specific amount of time in java?

前端 未结 5 583
借酒劲吻你
借酒劲吻你 2021-02-07 16:15

I have a scenario where i want a thread to sleep for specific amount of time.

Code:

    public void run(){
        try{
            //do something
               


        
5条回答
  •  Happy的楠姐
    2021-02-07 17:16

    I use it this way:

    So it is not necessary to wait the specific time to end.

    public void run(){
    
        try {
    
            //do something
    
            try{Thread.sleep(3000);}catch(Exception e){}
    
            //do something
    
        }catch(Exception e){}
    
    }
    

提交回复
热议问题