12.一个高层线程工具类(Timer)
Timer 是一个线程工具。它方便线程来调度任务马克-to-win在后台执行。可能会安排任务为一次性执行,或定期重复执行,下面给出例子:
例1.12.1
import java.util.Timer; import java.util.TimerTask; class TimExample { Timer timer; public TimExample(int seconds) { timer = new Timer(); /* public void schedule(TimerTask task,long delay) Schedules the specified task for execution after the specified delay.安排执行指定的任务在指定延迟后 */ timer.schedule(new CTask(), seconds * 1000); } // Inner class class CTask extends TimerTask { /* * public abstract void run() The action to be performed by this timer * task.被这个定时器所做的行为 */ public void run() { System.out.println("时间到!"); } } } public class TestMark_to_win { public static void main(String args[]) { new TimExample(3); System.out.println("here"); } }
更多请见:https://blog.csdn.net/qq_44639795/article/details/103095367
