1 package com.thread.test.thread;
2
3 import java.util.concurrent.ExecutorService;
4 import java.util.concurrent.LinkedBlockingQueue;
5 import java.util.concurrent.RejectedExecutionHandler;
6 import java.util.concurrent.ThreadLocalRandom;
7 import java.util.concurrent.ThreadPoolExecutor;
8 import java.util.concurrent.TimeUnit;
9
10
25 public class ThreadPoolFactoryTest
26 {
27 public static void main( String[] args )
28 {
29
37 ExecutorService enew = new ThreadPoolExecutor(5, 20, 0L,
38 TimeUnit.SECONDS,
39 new LinkedBlockingQueue<Runnable>(),
40 new RejectedExecutionHandler() {
41 public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
42 System.out.println("this is the exception execution begin");
43 executor.execute(r);
44 System.out.println("this is the exception execution end");
45 }
46 });
47
48 for (int i = 0; i < 100; i++) {
49 enew.execute(new Runnable() {
50 public void run() {
51 int l = ThreadLocalRandom.current().nextInt();
52 System.out.println("task..." + l + "begin");
53 try {
54 Thread.sleep(2000);
55 System.out.println("task..." + l + "end");
56 } catch (InterruptedException e) {
57 e.printStackTrace();
58 }
59 }
60 });
61 }
62 System.out.println("add end...");
63 }
64 }
项目地址:github.com/windwant/wi…