我最后想要的效果就是:
1
2
.....
100
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
package com.esen.test;
import edu.emory.mathcs.backport.java.util.concurrent.ArrayBlockingQueue;
import edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor;
import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;public class Test {  private ThreadPoolExecutor threadPool;  public Test() {
    threadPool = new 
    ThreadPoolExecutor(10, 20, 0, TimeUnit.SECONDS, new ArrayBlockingQueue(8), new ThreadPoolExecutor.DiscardOldestPolicy());
    
  }  /**
   * @param args
   * @throws InterruptedException 
   */
  public   void submit(final int i) throws InterruptedException {
    threadPool.execute(new Runnable() {
      public  void run() {
      System.out.println(i);
      }    });
   // Thread.sleep(1);本来这句话如果不注释,可以达到我的效果,可是如果这个任务,也就是run方法里面花费的时间很长,就不行了
  }  public static void main(String[] args) throws InterruptedException {
    Test t = new Test();
    for (int i = 0; i < 100; i++) {
      t.submit(i);
    
    }
    System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
  }}
输出结果是:
0
1
3
2
5
4
6
7
8
10
9
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
37
30
31
39
41
43
45
40
42
44
46
49
80
83
84
85
86
87
88
89
90
91
92
93
95
94
96
97
98
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
99
我的意思就是线程池把任务全部处理完,处理完以后我去干别的事情