java 定时器的使用
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.io.RandomAccessFile; import java.nio.ByteBuffer; import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; import java.nio.channels.FileLock; import java.util.Timer; import java.util.TimerTask; public class ProgramB { public static void main(String[] args) throws IOException { Timer timer = new Timer(); //里面的run方法名是固定写法 TimerTask task = new TimerTask() { @Override public void run() { System.out.println("定时任务被执行了"); } }; timer.schedule(task,0, 1000); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); reader.readLine(); } }
桂棹兮兰桨,击空明兮溯流光。