T X 0 Report post Posted March 27, 2010 import java.util.Timer;import java.util.TimerTask;public class TimerTest { public TimerTest() { getTimer().scheduleAtFixedRate( new TimerTask() { @Override public void run() { System.out.println("It has been 5 seconds."); } }, 5000, 5000); } public static void main(String[] args) { new TimerTest(); } public Timer getTimer() { return timer; } private Timer timer = new Timer();}The timer will wait 5 seconds, then display the message, then continuously wait 5 seconds and display the message over and over again. I actually think this is kind of cool since I didn't know about it before.Documentation: http://forums.xisto.com/no_longer_exists/http://forums.xisto.com/no_longer_exists/ Share this post Link to post Share on other sites
manish-mohania 0 Report post Posted March 28, 2010 yup, it is cool ... I found it useful for some tasks that require scheduling, like generating reports at regular intervals.There are open source api(s) for scheduling like Quartz, they provide additional features like:1. you can provide time interval in unix cron like format.2. Persistent jobs http://archive.oreilly.com/pub/a/java/archive/quartz.htmlFor J2ee applications, EJB's do not allow to create a new thread. TimerTask is a thread, so EJB's have their own way of scheduling tasks.http://www.onjava.com/pub/a/onjava/2004/10/13/j2ee-timers.htmlhttp://forums.xisto.com/no_longer_exists/ Share this post Link to post Share on other sites
T X 0 Report post Posted March 29, 2010 Yeah I have heard of Quartz however I never took the time to look into it.I usually use the Timer to process changes or repaint in my games so it's actually useful to me. Share this post Link to post Share on other sites