Biblioteca Java - Blame information for rev 8

Subversion Repositories:
Rev:
Rev Author Line No. Line
8 mihai 1 package threadpool1;
2  
3 import java.util.concurrent.ScheduledThreadPoolExecutor;
4 import java.util.concurrent.TimeUnit;
5  
6 /**
7  * A ThreadPoolExecutor that can additionally schedule commands to run after a given delay, or to execute periodically.
8  * This class is preferable to Timer  when multiple worker threads are needed, or when the additional flexibility or capabilities
9  * of ThreadPoolExecutor (which this class extends) are required.
10  *
11  * Delayed tasks execute no sooner than they are enabled, but without any real-time guarantees about when, after they are enabled,
12  * they will commence. Tasks scheduled for exactly the same execution time are enabled in first-in-first-out (FIFO) order of
13  * submission.
14  *
15  * @author mihai
16  *
17  */
18  
19 public class Main{
20  
21   public static void main(String args[]) {
22     ScheduledThreadPoolExecutor stpe = new ScheduledThreadPoolExecutor(5);
23  
24     stpe.scheduleAtFixedRate(new Job1(), 0, 5, TimeUnit.SECONDS);
25     stpe.scheduleAtFixedRate(new Job2(), 1, 2, TimeUnit.SECONDS);
26   }
27 }
28  
29 class Job1 implements Runnable {
30   public void run() {
31     System.out.println("Job 1");
32   }
33 }
34  
35 class Job2 implements Runnable {
36   public void run() {
37       for(int i=-3;i<3;i++){
38         System.out.println(i);
39       }
40   }
41 }