JDK1.5 provides a mechanism to create a pool a scheduled task : ScheduledThreadPoolExecutor « Thread « Java Tutorial






import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Main{

  public static void main(String args[]) {
    ScheduledThreadPoolExecutor stpe = new ScheduledThreadPoolExecutor(5);
    
    stpe.scheduleAtFixedRate(new Job1(), 0, 5, TimeUnit.SECONDS);
    stpe.scheduleAtFixedRate(new Job2(), 1, 2, TimeUnit.SECONDS);
  }
}

class Job1 implements Runnable {
  public void run() {
    System.out.println("Job 1");
  }
}

class Job2 implements Runnable {
  public void run() {
      for(int i=0;i<99;i++){
        System.out.println(i);
      }
  }
}








10.15.ScheduledThreadPoolExecutor
10.15.1.JDK1.5 provides a mechanism to create a pool a scheduled task
10.15.2.Animation with ScheduledThreadPoolExecutorAnimation with ScheduledThreadPoolExecutor
10.15.3.Return a value from a thread.