How to Pass Arguments to Timertask Run Method

后端 未结 5 738
悲&欢浪女
悲&欢浪女 2021-01-12 21:45

I have a method and I want it to be scheduled for execution in later times. The scheduling time and method\'s arguments depend on user inputs.

I already have tried T

5条回答
  •  清酒与你
    2021-01-12 22:20

    You can write you own class which extends from TimerTask class and you can override run method.

    class MyTimerTask extends TimerTask  {
         String param;
    
         public MyTimerTask(String param) {
             this.param = param;
         }
    
         @Override
         public void run() {
             // You can do anything you want with param 
         }
    }
    

提交回复
热议问题