Is this how to schedule a java method to run 1 second later?

后端 未结 4 689
日久生厌
日久生厌 2021-02-05 17:34

In my method, I want to call another method that will run 1 second later. This is what I have.

final Timer timer = new Timer();

timer.schedule(new TimerTask() {         


        
4条回答
  •  粉色の甜心
    2021-02-05 18:00

    If you are not in UI thread, consider adding a very simple:

    try
    {
      Thread.sleep( 1000 );
    }//try
    catch( Exception ex)
    { ex.printStackTrace(); }//catch
    
    //call your method
    

提交回复
热议问题