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

前端 未结 5 906
盖世英雄少女心
盖世英雄少女心 2021-02-07 16:19

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

Code:

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


        
5条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-07 17:21

    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){}
    
    }
    

提交回复
热议问题