Code: Test class
public class MyTestTimer { public static Timer mTimer; public static void main(String[] args) { mTimer=new Timer(); MyTimerTask testTimer=new MyTimerTask(10000); mTimer.schedule(testTimer, 10000); } }
TimerTask task class
public class MyTimerTask extends TimerTask{ private int second; public MyTimerTask(int second) { this.second=second; } public void run() { System.out.println("我等你等了"+second+"秒"); } }
The above simple demo (sharing) of Timer and TimerTask in java is The editor has shared all the content with you. I hope it can give you a reference. I also hope that everyone will support the PHP Chinese website.
For more Java Timer and TimerTask simple demo (sharing) related articles, please pay attention to the PHP Chinese website!