Java: Wait for TimerTask to complete before continuing execution

后端 未结 3 1226
暖寄归人
暖寄归人 2021-01-23 13:08

I\'m having a bit of an annoying problem. Right now, I have a snippet of code that starts a thread, sets a timer within that thread, and then exits that thread and continues wit

3条回答
  •  囚心锁ツ
    2021-01-23 13:54

    You should use Thread.sleep function instead of TimeTask to halt execution.

    TimerTask is not meant to halt execution, its like a clock running in background. So for your requirement you should go for Thread.sleep.

提交回复
热议问题