Java.util.concurrent.ScheduledThreadPoolExecutor is JDK1.6 comes with a package that is powerful enough to enable timer and delay loading
Various functions and treatments better than timer
1. Timer:
Scheduledthreadpoolexecutor has a scheduleatfixedrate (command, InitialDelay, period, unit); method
Command: Executed thread (can own new one)
InitialDelay: Initialization execution delay time
Period: Time interval
Unit: Time type (e.g. Timeunit.seconds: Second execution, timeunit.days: number of days)
Specific code:
public static void Main (string[] args) {stthread.scheduleatfixedrate (new Runnable () {@Overridepublic void Run () {//TODO A Uto-generated method StubSystem.out.println (New Date ());}},20, 2, timeunit.seconds);}
2. Delay processing
Scheduledthreadpoolexecutor has a schedule (callable, delay, unit); Method
Callable: Callback method
Delay: Delayed time
Unit: Time type, same as unit of timer
Specific code:
Stthread.schedule ((roleprvlegetask) Springutils.getbean ("Roleprvlegetask"), 1, timeunit.seconds);
Scheduledthreadpoolexecutor implement timer and delay load function