Joke Collection Website - Blessing messages - What class is timertask in java?
What class is timertask in java?
TimerTask is an abstract class that implements the Runnable interface, representing a task that can be executed by a Timer.
The Timer class is a threading facility that can be used to schedule a task to be executed once or regularly repeated at a certain time or after a certain period of time. This function is used in conjunction with TimerTask. The TimerTask class is used to implement a task that is scheduled to be executed once or repeatedly by a Timer. Each Timer object corresponds to a thread, so the tasks performed by the timer should be completed quickly, otherwise the execution of subsequent tasks will be delayed.
void cancel()
// Terminate this timer and discard all currently scheduled tasks.
int purge()
//Remove all canceled tasks from this timer's task queue.
void schedule(TimerTask task, Date time)
//Schedule execution of the specified task at the specified time.
void schedule(TimerTask task, Date firstTime, long period)
//Schedule the specified task to start repeated fixed delay execution at the specified time.
void schedule(TimerTask task, long delay)
//Schedule execution of the specified task after the specified delay.
void schedule(TimerTask task, long delay, long period)
//Schedule the specified task for repeated fixed delay execution starting from the specified delay.
void scheduleAtFixedRate(TimerTask task, Date firstTime, long period)
//Schedule the specified task to start repeated fixed-rate execution at the specified time.
void scheduleAtFixedRate(TimerTask task, long delay, long period)
//Schedule the specified task to start repeated fixed-rate execution after the specified delay.
boolean cancel()
//Cancel this timer task.
abstract void run()
//The operation to be performed by this timer task.
long scheduledExecutionTime()
//Returns the most recent scheduled execution time of this task.
package zzs.time.demo;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimerTask;
public class MyTask extends TimerTask {
@Override
public void run() {
p>
// TODO Auto-generated method stub
SimpleDateFormat simpleDateFormat=null;
simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH: mm: ss: SSS ");
System.out.println("The current system time is: " simpleDateFormat.format(new Date()));
}
}
package zzs.time.demo;
import java.util.Timer;
public class TestTask {
/**
* @param args
* @throws InterruptedException
*/
public static void main( String[] args) throws InterruptedException {
// TODO Auto-generated method stub
Timer timer=new Timer();
MyTask myTask=new MyTask ();
timer.schedule(myTask, 1000, 2000);
// Thread.sleep(5000);
//timer.cancel( );
}
}
Running results:
The current system time is: 2011-07-10 15:37: 44:831
The current system time is: 2011-07-10 15:37:46:786
The current system time is: 2011-07-10 15:37: 48:786
The current system time is: 2011-07-
10 15:37:50:786
The current system time is: 2011-07-10 15:37:52:786
The current system time is: 2011-07- 10 15:37:54:786
- Related articles
- What do you mean you want money?
- Xiaomi mobile phone, how does miui open the software floating window?
- What if etc restricts the use?
- If the other party blackmails you, will you get a text message?
- What are the functions of Taobao Super Store Manager?
- I accidentally ran a red light and never received a violation message.
- How to pay a New Year call to your tutor?
- Happy Birthday Blessing WeChat SMS Template
- What should I do if I forget the password of Fujian Education Examinations Institute?
- How to get the WeChat applet out?