Source: http://www.cnblogs.com/wyqtomorrow/archive/2007/04/28/730978.aspx
1. In application development, periodic operations are often required, such as performing an operation every five minutes. The most convenient and efficient way to implement such operations is to use the java. util. Timer tool class.
Private java. util. Timer timer;
Timer = new timer (true );
Timer. Schedule (
New java. util. timertask () {public void run () {// server. checknewmail (); Method to operate}, 0, 5*60*1000 );
The first parameter is the method to be operated, the second parameter is to set the delay time, and the third parameter is the period setting. The operation is executed at intervals.
After using these lines of code, Timer itself will call the server. checknewmail () method every five minutes without starting the thread. Timer itself is also multi-threaded synchronization. Multiple Threads can share one timer without external synchronization code.
2,
(1) timer. Schedule (timertask task, date time) is scheduled to execute the specified task at the specified time.
(2) timer. Schedule (timertask task, date firsttime, long period) arranges the specified task to start repeated fixed delay execution at the specified time.
(3) timer. Schedule (timertask task, long delay) arranges to execute the specified task after the specified delay.
(4) timer. Schedule (timertask task, long delay, long period) schedules the specified task to start repeated fixed delay execution after the specified delay.
(5) timer. scheduleatfixedrate (timertask task, date firsttime, long period) Schedule the specified task to start repeating at a fixed rate.
(6) timer. scheduleatfixedrate (timertask task, long delay, long period) arranges the specified task to start repeated execution at a fixed rate after the specified delay.