Java多線程13 自定義線程池

Java多線程目錄
1.任務(wù)隊(duì)列
2.拒絕策略(拋出異常蜂科、直接丟棄眶熬、阻塞大莫、臨時(shí)隊(duì)列)
3.init( min )
4.active
5.max

min<=active<=max

package chapter13;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class SimpleThreadPool {

    public final static DiscardPolicy DEFAULT_DISCARD_POLICY = () -> {
        throw new DiscardException("Discard This Task.");
    };
    private final static int DEFAULT_SIZE = 10;
    //設(shè)置線程任務(wù)最大值
    private final static int DEFAULT_TASK_QUEUE_SIZE = 2000;
    private final static LinkedList<Runnable> TASK_QUEUE = new LinkedList<>();
    private final static String THREAD_PREFIX = "SIMPLE_THREAD_POOL-";
    private final static ThreadGroup GROUP = new ThreadGroup("Pool_Group");
    private final static List<WorkerTask> THREAD_QUEUE = new ArrayList<>();
    private static volatile int seq = 0;
    private final int size;
    //隊(duì)列大小
    private final int queueSize;
    private final DiscardPolicy discardPolicy;

    private volatile boolean destroy = false;

    public SimpleThreadPool() {
        this(DEFAULT_SIZE, DEFAULT_TASK_QUEUE_SIZE, DEFAULT_DISCARD_POLICY);
    }

    public SimpleThreadPool(int size, int queueSize, DiscardPolicy discardPolicy) {
        this.size = size;
        this.queueSize = queueSize;
        this.discardPolicy = discardPolicy;
        init();
    }



    private void init() {

        for (int i = 0; i < size; i++) {
            createWorkTask();
        }
    }

    public void submit(Runnable runnable) {
        if(destroy) throw new IllegalStateException("The thread pool already destroy and not allow submit task.");
        synchronized (TASK_QUEUE) {
            if (TASK_QUEUE.size() > queueSize) discardPolicy.discard();
            TASK_QUEUE.addLast(runnable);
            TASK_QUEUE.notifyAll();
        }
    }

    private void createWorkTask() {
        WorkerTask task = new WorkerTask(GROUP, THREAD_PREFIX + (seq++));
        task.start();
        THREAD_QUEUE.add(task);
    }

    public void shutdown() throws InterruptedException {
        while (!TASK_QUEUE.isEmpty()) {
            Thread.sleep(50);
        }

        int initVal = THREAD_QUEUE.size();
        while (initVal > 0) {
            for (WorkerTask task : THREAD_QUEUE) {
                if (task.getTaskState() == TaskState.BLOCKED) {
                    task.interrupt();
                    task.close();
                    initVal--;
                } else {
                    Thread.sleep(10);
                }
            }
        }
        this.destroy = true;
        System.out.println("The thread pool disposed.");
    }

    public int getSize() {
        return size;
    }

    public int getQueueSize() {
        return queueSize;
    }

    public boolean destory() {
        return this.destroy;
    }

    private enum TaskState {
        FREE, RUNNING, BLOCKED, DEAD
    }

    public interface DiscardPolicy {

        void discard() throws DiscardException;
    }

    public static class DiscardException extends RuntimeException {

        public DiscardException(String message) {
            super(message);
        }
    }

    private static class WorkerTask extends Thread {

        private volatile TaskState taskState = TaskState.FREE;

        public WorkerTask(ThreadGroup group, String name) {
            super(group, name);
        }

        public TaskState getTaskState() {
            return this.taskState;
        }

        public void run() {
            OUTER:
            while (this.taskState != TaskState.DEAD) {

                Runnable runnable;
                synchronized (TASK_QUEUE) {
                    while (TASK_QUEUE.isEmpty()) {
                        try {
                            taskState = TaskState.BLOCKED;
                            TASK_QUEUE.wait();
                        } catch (InterruptedException e) {
                            break OUTER;
                        }
                    }

                    runnable = TASK_QUEUE.removeFirst();
                }

                if (runnable != null) {
                    taskState = TaskState.RUNNING;
                    runnable.run();
                    taskState = TaskState.FREE;
                }
            }
        }

        public void close() {
            this.taskState = TaskState.DEAD;
        }
    }



    public static void main(String[] args) throws InterruptedException {
        SimpleThreadPool threadPool = new SimpleThreadPool();
        for (int i = 0; i < 40; i++) {

            int finalI = i;
            threadPool.submit(() -> {
                System.out.println("The runnable " + finalI + " be serviced by " + Thread.currentThread() + " start.");
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("The runnable " + finalI + " be serviced by " + Thread.currentThread() + " finished.");
            });

            System.out.println("======================");

        }
        Thread.sleep(4000);
        threadPool.shutdown();
        threadPool.submit(()->System.out.println("============="));
    }


}
======================
======================
The runnable 0 be serviced by Thread[SIMPLE_THREAD_POOL-9,5,Pool_Group] start.
======================
The runnable 2 be serviced by Thread[SIMPLE_THREAD_POOL-1,5,Pool_Group] start.
The runnable 1 be serviced by Thread[SIMPLE_THREAD_POOL-4,5,Pool_Group] start.
The runnable 3 be serviced by Thread[SIMPLE_THREAD_POOL-8,5,Pool_Group] start.
======================
======================
======================
The runnable 5 be serviced by Thread[SIMPLE_THREAD_POOL-2,5,Pool_Group] start.
The runnable 6 be serviced by Thread[SIMPLE_THREAD_POOL-6,5,Pool_Group] start.
======================
======================
The runnable 7 be serviced by Thread[SIMPLE_THREAD_POOL-3,5,Pool_Group] start.
The runnable 4 be serviced by Thread[SIMPLE_THREAD_POOL-0,5,Pool_Group] start.
The runnable 8 be serviced by Thread[SIMPLE_THREAD_POOL-7,5,Pool_Group] start.
======================
======================
======================
======================
The runnable 9 be serviced by Thread[SIMPLE_THREAD_POOL-5,5,Pool_Group] start.
======================
======================
======================
======================
======================
======================
======================
======================
======================
======================
======================
======================
======================
======================
======================
======================
======================
======================
======================
======================
======================
======================
======================
======================
======================
======================
======================
======================
The runnable 7 be serviced by Thread[SIMPLE_THREAD_POOL-3,5,Pool_Group] finished.
The runnable 10 be serviced by Thread[SIMPLE_THREAD_POOL-3,5,Pool_Group] start.
The runnable 6 be serviced by Thread[SIMPLE_THREAD_POOL-6,5,Pool_Group] finished.
The runnable 11 be serviced by Thread[SIMPLE_THREAD_POOL-6,5,Pool_Group] start.
The runnable 3 be serviced by Thread[SIMPLE_THREAD_POOL-8,5,Pool_Group] finished.
The runnable 12 be serviced by Thread[SIMPLE_THREAD_POOL-8,5,Pool_Group] start.
The runnable 5 be serviced by Thread[SIMPLE_THREAD_POOL-2,5,Pool_Group] finished.
The runnable 0 be serviced by Thread[SIMPLE_THREAD_POOL-9,5,Pool_Group] finished.
The runnable 14 be serviced by Thread[SIMPLE_THREAD_POOL-9,5,Pool_Group] start.
The runnable 2 be serviced by Thread[SIMPLE_THREAD_POOL-1,5,Pool_Group] finished.
The runnable 15 be serviced by Thread[SIMPLE_THREAD_POOL-1,5,Pool_Group] start.
The runnable 8 be serviced by Thread[SIMPLE_THREAD_POOL-7,5,Pool_Group] finished.
The runnable 16 be serviced by Thread[SIMPLE_THREAD_POOL-7,5,Pool_Group] start.
The runnable 4 be serviced by Thread[SIMPLE_THREAD_POOL-0,5,Pool_Group] finished.
The runnable 17 be serviced by Thread[SIMPLE_THREAD_POOL-0,5,Pool_Group] start.
The runnable 9 be serviced by Thread[SIMPLE_THREAD_POOL-5,5,Pool_Group] finished.
The runnable 1 be serviced by Thread[SIMPLE_THREAD_POOL-4,5,Pool_Group] finished.
The runnable 19 be serviced by Thread[SIMPLE_THREAD_POOL-4,5,Pool_Group] start.
The runnable 18 be serviced by Thread[SIMPLE_THREAD_POOL-5,5,Pool_Group] start.
The runnable 13 be serviced by Thread[SIMPLE_THREAD_POOL-2,5,Pool_Group] start.
The runnable 10 be serviced by Thread[SIMPLE_THREAD_POOL-3,5,Pool_Group] finished.
The runnable 14 be serviced by Thread[SIMPLE_THREAD_POOL-9,5,Pool_Group] finished.
The runnable 11 be serviced by Thread[SIMPLE_THREAD_POOL-6,5,Pool_Group] finished.
The runnable 22 be serviced by Thread[SIMPLE_THREAD_POOL-6,5,Pool_Group] start.
The runnable 12 be serviced by Thread[SIMPLE_THREAD_POOL-8,5,Pool_Group] finished.
The runnable 21 be serviced by Thread[SIMPLE_THREAD_POOL-9,5,Pool_Group] start.
The runnable 20 be serviced by Thread[SIMPLE_THREAD_POOL-3,5,Pool_Group] start.
The runnable 23 be serviced by Thread[SIMPLE_THREAD_POOL-8,5,Pool_Group] start.
The runnable 15 be serviced by Thread[SIMPLE_THREAD_POOL-1,5,Pool_Group] finished.
The runnable 24 be serviced by Thread[SIMPLE_THREAD_POOL-1,5,Pool_Group] start.
The runnable 17 be serviced by Thread[SIMPLE_THREAD_POOL-0,5,Pool_Group] finished.
The runnable 18 be serviced by Thread[SIMPLE_THREAD_POOL-5,5,Pool_Group] finished.
The runnable 25 be serviced by Thread[SIMPLE_THREAD_POOL-0,5,Pool_Group] start.
The runnable 13 be serviced by Thread[SIMPLE_THREAD_POOL-2,5,Pool_Group] finished.
The runnable 16 be serviced by Thread[SIMPLE_THREAD_POOL-7,5,Pool_Group] finished.
The runnable 19 be serviced by Thread[SIMPLE_THREAD_POOL-4,5,Pool_Group] finished.
The runnable 28 be serviced by Thread[SIMPLE_THREAD_POOL-7,5,Pool_Group] start.
The runnable 27 be serviced by Thread[SIMPLE_THREAD_POOL-2,5,Pool_Group] start.
The runnable 26 be serviced by Thread[SIMPLE_THREAD_POOL-5,5,Pool_Group] start.
The runnable 29 be serviced by Thread[SIMPLE_THREAD_POOL-4,5,Pool_Group] start.
The runnable 22 be serviced by Thread[SIMPLE_THREAD_POOL-6,5,Pool_Group] finished.
The runnable 30 be serviced by Thread[SIMPLE_THREAD_POOL-6,5,Pool_Group] start.
The runnable 20 be serviced by Thread[SIMPLE_THREAD_POOL-3,5,Pool_Group] finished.
The runnable 31 be serviced by Thread[SIMPLE_THREAD_POOL-3,5,Pool_Group] start.
The runnable 23 be serviced by Thread[SIMPLE_THREAD_POOL-8,5,Pool_Group] finished.
The runnable 21 be serviced by Thread[SIMPLE_THREAD_POOL-9,5,Pool_Group] finished.
The runnable 32 be serviced by Thread[SIMPLE_THREAD_POOL-8,5,Pool_Group] start.
The runnable 33 be serviced by Thread[SIMPLE_THREAD_POOL-9,5,Pool_Group] start.
The runnable 24 be serviced by Thread[SIMPLE_THREAD_POOL-1,5,Pool_Group] finished.
The runnable 34 be serviced by Thread[SIMPLE_THREAD_POOL-1,5,Pool_Group] start.
The runnable 25 be serviced by Thread[SIMPLE_THREAD_POOL-0,5,Pool_Group] finished.
The runnable 29 be serviced by Thread[SIMPLE_THREAD_POOL-4,5,Pool_Group] finished.
The runnable 27 be serviced by Thread[SIMPLE_THREAD_POOL-2,5,Pool_Group] finished.
The runnable 35 be serviced by Thread[SIMPLE_THREAD_POOL-0,5,Pool_Group] start.
The runnable 26 be serviced by Thread[SIMPLE_THREAD_POOL-5,5,Pool_Group] finished.
The runnable 28 be serviced by Thread[SIMPLE_THREAD_POOL-7,5,Pool_Group] finished.
The runnable 39 be serviced by Thread[SIMPLE_THREAD_POOL-7,5,Pool_Group] start.
The runnable 38 be serviced by Thread[SIMPLE_THREAD_POOL-5,5,Pool_Group] start.
The runnable 37 be serviced by Thread[SIMPLE_THREAD_POOL-2,5,Pool_Group] start.
The runnable 36 be serviced by Thread[SIMPLE_THREAD_POOL-4,5,Pool_Group] start.
The runnable 33 be serviced by Thread[SIMPLE_THREAD_POOL-9,5,Pool_Group] finished.
The runnable 32 be serviced by Thread[SIMPLE_THREAD_POOL-8,5,Pool_Group] finished.
The runnable 31 be serviced by Thread[SIMPLE_THREAD_POOL-3,5,Pool_Group] finished.
The runnable 30 be serviced by Thread[SIMPLE_THREAD_POOL-6,5,Pool_Group] finished.
The runnable 39 be serviced by Thread[SIMPLE_THREAD_POOL-7,5,Pool_Group] finished.
The runnable 34 be serviced by Thread[SIMPLE_THREAD_POOL-1,5,Pool_Group] finished.
The runnable 38 be serviced by Thread[SIMPLE_THREAD_POOL-5,5,Pool_Group] finished.
The runnable 36 be serviced by Thread[SIMPLE_THREAD_POOL-4,5,Pool_Group] finished.
The runnable 37 be serviced by Thread[SIMPLE_THREAD_POOL-2,5,Pool_Group] finished.
The runnable 35 be serviced by Thread[SIMPLE_THREAD_POOL-0,5,Pool_Group] finished.
The thread pool disposed.
Exception in thread "main" java.lang.IllegalStateException: The thread pool already destroy and not allow submit task.
    at chapter13.SimpleThreadPool.submit(SimpleThreadPool.java:48)
    at chapter13.SimpleThreadPool.main(SimpleThreadPool.java:176)

線程池本身就是一個(gè)線程

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class SimpleThreadPool extends Thread {

    public final static DiscardPolicy DEFAULT_DISCARD_POLICY = () -> {
        throw new DiscardException("Discard This Task.");
    };
    //設(shè)置線程任務(wù)最大值
    private final static int DEFAULT_TASK_QUEUE_SIZE = 2000;
    /**
     * 任務(wù)隊(duì)列
     */
    private final static LinkedList<Runnable> TASK_QUEUE = new LinkedList<>();
    private final static String THREAD_PREFIX = "SIMPLE_THREAD_POOL-";
    /**
     * 線程組
     */
    private final static ThreadGroup GROUP = new ThreadGroup("Pool_Group");
    private final static List<WorkerTask> THREAD_QUEUE = new ArrayList<>();
    private static volatile int seq = 0;
    //隊(duì)列大小
    private final int queueSize;
    private final DiscardPolicy discardPolicy;
    private int size;
    private volatile boolean destroy = false;

    /**
     * 最小線程數(shù)
     */
    private int min;
    /**
     * 最大線程數(shù)
     */
    private int max;
    /**
     * 線程活躍數(shù)
     */
    private int active;

    public SimpleThreadPool() {
        this(4, 8, 12, DEFAULT_TASK_QUEUE_SIZE, DEFAULT_DISCARD_POLICY);
    }

    public SimpleThreadPool(int min, int active, int max, int queueSize, DiscardPolicy discardPolicy) {
        this.min = min;
        this.active = active;
        this.max = max;
        this.queueSize = queueSize;
        this.discardPolicy = discardPolicy;
        init();
    }

    private void init() {

        for (int i = 0; i < this.min; i++) {
            createWorkTask();
        }
        /**
         * 默認(rèn)線程大小為最小線程數(shù)
         */
        this.size = min;
        this.start();
    }

    public void submit(Runnable runnable) {
        if (destroy) throw new IllegalStateException("The thread pool already destroy and not allow submit task.");
        synchronized (TASK_QUEUE) {
            if (TASK_QUEUE.size() > queueSize) discardPolicy.discard();
            TASK_QUEUE.addLast(runnable);
            TASK_QUEUE.notifyAll();
        }
    }

    private void createWorkTask() {
        WorkerTask task = new WorkerTask(GROUP, THREAD_PREFIX + (seq++));
        task.start();
        THREAD_QUEUE.add(task);
    }


    public void shutdown() throws InterruptedException {

        while (!TASK_QUEUE.isEmpty()) {
            Thread.sleep(50);
        }
        //加鎖 對線程進(jìn)行操作唯一
        synchronized (THREAD_QUEUE) {
            int initVal = THREAD_QUEUE.size();
            while (initVal > 0) {
                for (WorkerTask task : THREAD_QUEUE) {
                    if (task.getTaskState() == TaskState.BLOCKED) {
                        task.interrupt();
                        task.close();
                        initVal--;
                    } else {
                        Thread.sleep(10);
                    }
                }
            }

        }
        this.destroy = true;
        System.out.println("The thread pool disposed.");
    }

    public int getSize() {
        return size;
    }

    public int getQueueSize() {
        return queueSize;
    }

    public boolean isDestory() {
        return this.destroy;
    }

    public int getMin() {
        return min;
    }

    public int getMax() {
        return max;
    }

    public int getActive() {
        return active;
    }

    @Override
    public void run() {
        while (!destroy) {
            System.out.printf("Pool#Min:%d,Active:%d,Max:%d,Current:%d,QueueSize:%d\n",
                    this.min, this.active, this.max, this.size, TASK_QUEUE.size());


            try {
                Thread.sleep(5_000L);
                //讓線程池以最大活躍數(shù)運(yùn)行
                if (TASK_QUEUE.size() > active && size < active) {
                    for (int i = size; i < active; i++) {
                        createWorkTask();
                    }
                    System.out.println("The pool incremented to active.");

                    size = active;
                    //讓線程池以最大線程數(shù)運(yùn)行
                } else if (TASK_QUEUE.size() > max && size < max) {
                    for (int i = size; i < max; i++) {
                        createWorkTask();
                    }
                    System.out.println("The pool incremented to max.");
                    //讓size以最大活躍數(shù)運(yùn)行
                    size = max;
                }


                /**
                 * 釋放線程
                 * 加鎖 防止submit的時(shí)候 有其他的操作
                 */
                synchronized (TASK_QUEUE) {
                    if (TASK_QUEUE.isEmpty() && size > active) {
                        System.out.println("==========Reduce=========");
                        int releaseSize = size - active;
                        for (Iterator<WorkerTask> it = THREAD_QUEUE.iterator(); it.hasNext(); ) {
                            if (releaseSize <= 0) {
                                break;
                            }
                            WorkerTask task = it.next();
                            task.close();
                            task.interrupt();
                            it.remove();
                            releaseSize--;
                        }

                        size = active;
                    }
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    private enum TaskState {
        FREE, RUNNING, BLOCKED, DEAD
    }

    public interface DiscardPolicy {

        void discard() throws DiscardException;
    }

    public static class DiscardException extends RuntimeException {

        public DiscardException(String message) {
            super(message);
        }
    }

    private static class WorkerTask extends Thread {

        private volatile TaskState taskState = TaskState.FREE;

        public WorkerTask(ThreadGroup group, String name) {
            super(group, name);
        }

        public TaskState getTaskState() {
            return this.taskState;
        }

        public void run() {
            OUTER:
            while (this.taskState != TaskState.DEAD) {

                Runnable runnable;
                synchronized (TASK_QUEUE) {
                    while (TASK_QUEUE.isEmpty()) {
                        try {
                            taskState = TaskState.BLOCKED;
                            TASK_QUEUE.wait();
                        } catch (InterruptedException e) {
                            System.out.println("Closed.");
                            break OUTER;
                        }
                    }

                    runnable = TASK_QUEUE.removeFirst();
                }

                if (runnable != null) {
                    taskState = TaskState.RUNNING;
                    runnable.run();
                    taskState = TaskState.FREE;
                }
            }
        }

        public void close() {
            this.taskState = TaskState.DEAD;
        }
    }

    public static void main(String[] args) throws InterruptedException {
        SimpleThreadPool threadPool = new SimpleThreadPool();
        for (int i = 0; i < 40; i++) {

            int finalI = i;
            threadPool.submit(() -> {
                System.out.println("The runnable " + finalI + " be serviced by " + Thread.currentThread() + " start.");
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("The runnable " + finalI + " be serviced by " + Thread.currentThread() + " finished.");
            });

            //System.out.println("======================");

        }
//        Thread.sleep(4000);
//        threadPool.shutdown();
//        threadPool.submit(() -> System.out.println("============="));
    }
}
Pool#Min:4,Active:8,Max:12,Current:4,QueueSize:0
The runnable 2 be serviced by Thread[SIMPLE_THREAD_POOL-1,5,Pool_Group] start.
The runnable 3 be serviced by Thread[SIMPLE_THREAD_POOL-0,5,Pool_Group] start.
The runnable 1 be serviced by Thread[SIMPLE_THREAD_POOL-2,5,Pool_Group] start.
The runnable 0 be serviced by Thread[SIMPLE_THREAD_POOL-3,5,Pool_Group] start.
The runnable 3 be serviced by Thread[SIMPLE_THREAD_POOL-0,5,Pool_Group] finished.
The runnable 4 be serviced by Thread[SIMPLE_THREAD_POOL-0,5,Pool_Group] start.
The runnable 1 be serviced by Thread[SIMPLE_THREAD_POOL-2,5,Pool_Group] finished.
The runnable 5 be serviced by Thread[SIMPLE_THREAD_POOL-2,5,Pool_Group] start.
The runnable 2 be serviced by Thread[SIMPLE_THREAD_POOL-1,5,Pool_Group] finished.
The runnable 6 be serviced by Thread[SIMPLE_THREAD_POOL-1,5,Pool_Group] start.
The runnable 0 be serviced by Thread[SIMPLE_THREAD_POOL-3,5,Pool_Group] finished.
The runnable 7 be serviced by Thread[SIMPLE_THREAD_POOL-3,5,Pool_Group] start.
The runnable 8 be serviced by Thread[SIMPLE_THREAD_POOL-4,5,Pool_Group] start.
The runnable 9 be serviced by Thread[SIMPLE_THREAD_POOL-5,5,Pool_Group] start.
The pool incremented to active.
The runnable 10 be serviced by Thread[SIMPLE_THREAD_POOL-6,5,Pool_Group] start.
Pool#Min:4,Active:8,Max:12,Current:8,QueueSize:29
The runnable 11 be serviced by Thread[SIMPLE_THREAD_POOL-7,5,Pool_Group] start.
The runnable 4 be serviced by Thread[SIMPLE_THREAD_POOL-0,5,Pool_Group] finished.
The runnable 12 be serviced by Thread[SIMPLE_THREAD_POOL-0,5,Pool_Group] start.
The runnable 7 be serviced by Thread[SIMPLE_THREAD_POOL-3,5,Pool_Group] finished.
The runnable 13 be serviced by Thread[SIMPLE_THREAD_POOL-3,5,Pool_Group] start.
The runnable 5 be serviced by Thread[SIMPLE_THREAD_POOL-2,5,Pool_Group] finished.
The runnable 6 be serviced by Thread[SIMPLE_THREAD_POOL-1,5,Pool_Group] finished.
The runnable 14 be serviced by Thread[SIMPLE_THREAD_POOL-2,5,Pool_Group] start.
The runnable 15 be serviced by Thread[SIMPLE_THREAD_POOL-1,5,Pool_Group] start.
The runnable 9 be serviced by Thread[SIMPLE_THREAD_POOL-5,5,Pool_Group] finished.
The runnable 16 be serviced by Thread[SIMPLE_THREAD_POOL-5,5,Pool_Group] start.
The runnable 8 be serviced by Thread[SIMPLE_THREAD_POOL-4,5,Pool_Group] finished.
The runnable 10 be serviced by Thread[SIMPLE_THREAD_POOL-6,5,Pool_Group] finished.
The runnable 18 be serviced by Thread[SIMPLE_THREAD_POOL-6,5,Pool_Group] start.
The runnable 17 be serviced by Thread[SIMPLE_THREAD_POOL-4,5,Pool_Group] start.
The runnable 11 be serviced by Thread[SIMPLE_THREAD_POOL-7,5,Pool_Group] finished.
The runnable 19 be serviced by Thread[SIMPLE_THREAD_POOL-7,5,Pool_Group] start.
The runnable 14 be serviced by Thread[SIMPLE_THREAD_POOL-2,5,Pool_Group] finished.
The runnable 20 be serviced by Thread[SIMPLE_THREAD_POOL-2,5,Pool_Group] start.
The runnable 15 be serviced by Thread[SIMPLE_THREAD_POOL-1,5,Pool_Group] finished.
The runnable 13 be serviced by Thread[SIMPLE_THREAD_POOL-3,5,Pool_Group] finished.
The runnable 22 be serviced by Thread[SIMPLE_THREAD_POOL-3,5,Pool_Group] start.
The runnable 12 be serviced by Thread[SIMPLE_THREAD_POOL-0,5,Pool_Group] finished.
The runnable 21 be serviced by Thread[SIMPLE_THREAD_POOL-1,5,Pool_Group] start.
The runnable 23 be serviced by Thread[SIMPLE_THREAD_POOL-0,5,Pool_Group] start.
The runnable 24 be serviced by Thread[SIMPLE_THREAD_POOL-8,5,Pool_Group] start.
The runnable 25 be serviced by Thread[SIMPLE_THREAD_POOL-9,5,Pool_Group] start.
The runnable 26 be serviced by Thread[SIMPLE_THREAD_POOL-10,5,Pool_Group] start.
The pool incremented to max.
Pool#Min:4,Active:8,Max:12,Current:12,QueueSize:13
The runnable 27 be serviced by Thread[SIMPLE_THREAD_POOL-11,5,Pool_Group] start.
The runnable 18 be serviced by Thread[SIMPLE_THREAD_POOL-6,5,Pool_Group] finished.
The runnable 19 be serviced by Thread[SIMPLE_THREAD_POOL-7,5,Pool_Group] finished.
The runnable 29 be serviced by Thread[SIMPLE_THREAD_POOL-7,5,Pool_Group] start.
The runnable 16 be serviced by Thread[SIMPLE_THREAD_POOL-5,5,Pool_Group] finished.
The runnable 30 be serviced by Thread[SIMPLE_THREAD_POOL-5,5,Pool_Group] start.
The runnable 17 be serviced by Thread[SIMPLE_THREAD_POOL-4,5,Pool_Group] finished.
The runnable 31 be serviced by Thread[SIMPLE_THREAD_POOL-4,5,Pool_Group] start.
The runnable 28 be serviced by Thread[SIMPLE_THREAD_POOL-6,5,Pool_Group] start.
The runnable 20 be serviced by Thread[SIMPLE_THREAD_POOL-2,5,Pool_Group] finished.
The runnable 32 be serviced by Thread[SIMPLE_THREAD_POOL-2,5,Pool_Group] start.
The runnable 23 be serviced by Thread[SIMPLE_THREAD_POOL-0,5,Pool_Group] finished.
The runnable 33 be serviced by Thread[SIMPLE_THREAD_POOL-0,5,Pool_Group] start.
The runnable 21 be serviced by Thread[SIMPLE_THREAD_POOL-1,5,Pool_Group] finished.
The runnable 22 be serviced by Thread[SIMPLE_THREAD_POOL-3,5,Pool_Group] finished.
The runnable 34 be serviced by Thread[SIMPLE_THREAD_POOL-1,5,Pool_Group] start.
The runnable 35 be serviced by Thread[SIMPLE_THREAD_POOL-3,5,Pool_Group] start.
The runnable 24 be serviced by Thread[SIMPLE_THREAD_POOL-8,5,Pool_Group] finished.
The runnable 25 be serviced by Thread[SIMPLE_THREAD_POOL-9,5,Pool_Group] finished.
The runnable 36 be serviced by Thread[SIMPLE_THREAD_POOL-8,5,Pool_Group] start.
The runnable 26 be serviced by Thread[SIMPLE_THREAD_POOL-10,5,Pool_Group] finished.
The runnable 37 be serviced by Thread[SIMPLE_THREAD_POOL-9,5,Pool_Group] start.
The runnable 38 be serviced by Thread[SIMPLE_THREAD_POOL-10,5,Pool_Group] start.
The runnable 27 be serviced by Thread[SIMPLE_THREAD_POOL-11,5,Pool_Group] finished.
The runnable 39 be serviced by Thread[SIMPLE_THREAD_POOL-11,5,Pool_Group] start.
The runnable 29 be serviced by Thread[SIMPLE_THREAD_POOL-7,5,Pool_Group] finished.
The runnable 31 be serviced by Thread[SIMPLE_THREAD_POOL-4,5,Pool_Group] finished.
The runnable 30 be serviced by Thread[SIMPLE_THREAD_POOL-5,5,Pool_Group] finished.
The runnable 28 be serviced by Thread[SIMPLE_THREAD_POOL-6,5,Pool_Group] finished.
==========Reduce=========
The runnable 35 be serviced by Thread[SIMPLE_THREAD_POOL-3,5,Pool_Group] finished.
The runnable 32 be serviced by Thread[SIMPLE_THREAD_POOL-2,5,Pool_Group] finished.
The runnable 33 be serviced by Thread[SIMPLE_THREAD_POOL-0,5,Pool_Group] finished.
The runnable 34 be serviced by Thread[SIMPLE_THREAD_POOL-1,5,Pool_Group] finished.
Closed.
Pool#Min:4,Active:8,Max:12,Current:8,QueueSize:0
Closed.
Closed.
Closed.
The runnable 38 be serviced by Thread[SIMPLE_THREAD_POOL-10,5,Pool_Group] finished.
The runnable 36 be serviced by Thread[SIMPLE_THREAD_POOL-8,5,Pool_Group] finished.
The runnable 37 be serviced by Thread[SIMPLE_THREAD_POOL-9,5,Pool_Group] finished.
The runnable 39 be serviced by Thread[SIMPLE_THREAD_POOL-11,5,Pool_Group] finished.
Pool#Min:4,Active:8,Max:12,Current:8,QueueSize:0
Pool#Min:4,Active:8,Max:12,Current:8,QueueSize:0
Pool#Min:4,Active:8,Max:12,Current:8,QueueSize:0
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市偿荷,隨后出現(xiàn)的幾起案子枝誊,更是在濱河造成了極大的恐慌况芒,老刑警劉巖,帶你破解...
    沈念sama閱讀 206,214評論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件叶撒,死亡現(xiàn)場離奇詭異绝骚,居然都是意外死亡耐版,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,307評論 2 382
  • 文/潘曉璐 我一進(jìn)店門压汪,熙熙樓的掌柜王于貴愁眉苦臉地迎上來粪牲,“玉大人,你說我怎么就攤上這事止剖∠傺簦” “怎么了?”我有些...
    開封第一講書人閱讀 152,543評論 0 341
  • 文/不壞的土叔 我叫張陵穿香,是天一觀的道長亭引。 經(jīng)常有香客問我,道長皮获,這世上最難降的妖魔是什么焙蚓? 我笑而不...
    開封第一講書人閱讀 55,221評論 1 279
  • 正文 為了忘掉前任,我火速辦了婚禮洒宝,結(jié)果婚禮上购公,老公的妹妹穿的比我還像新娘。我一直安慰自己待德,他們只是感情好君丁,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,224評論 5 371
  • 文/花漫 我一把揭開白布枫夺。 她就那樣靜靜地躺著将宪,像睡著了一般。 火紅的嫁衣襯著肌膚如雪橡庞。 梳的紋絲不亂的頭發(fā)上较坛,一...
    開封第一講書人閱讀 49,007評論 1 284
  • 那天,我揣著相機(jī)與錄音扒最,去河邊找鬼丑勤。 笑死,一個(gè)胖子當(dāng)著我的面吹牛吧趣,可吹牛的內(nèi)容都是我干的法竞。 我是一名探鬼主播,決...
    沈念sama閱讀 38,313評論 3 399
  • 文/蒼蘭香墨 我猛地睜開眼强挫,長吁一口氣:“原來是場噩夢啊……” “哼岔霸!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起俯渤,我...
    開封第一講書人閱讀 36,956評論 0 259
  • 序言:老撾萬榮一對情侶失蹤呆细,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后八匠,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體絮爷,經(jīng)...
    沈念sama閱讀 43,441評論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡趴酣,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,925評論 2 323
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了坑夯。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片岖寞。...
    茶點(diǎn)故事閱讀 38,018評論 1 333
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖柜蜈,靈堂內(nèi)的尸體忽然破棺而出慎璧,到底是詐尸還是另有隱情,我是刑警寧澤跨释,帶...
    沈念sama閱讀 33,685評論 4 322
  • 正文 年R本政府宣布胸私,位于F島的核電站,受9級特大地震影響鳖谈,放射性物質(zhì)發(fā)生泄漏岁疼。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,234評論 3 307
  • 文/蒙蒙 一缆娃、第九天 我趴在偏房一處隱蔽的房頂上張望捷绒。 院中可真熱鬧,春花似錦贯要、人聲如沸暖侨。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,240評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽字逗。三九已至,卻和暖如春宅广,著一層夾襖步出監(jiān)牢的瞬間葫掉,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,464評論 1 261
  • 我被黑心中介騙來泰國打工跟狱, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留俭厚,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 45,467評論 2 352
  • 正文 我出身青樓驶臊,卻偏偏與公主長得像挪挤,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個(gè)殘疾皇子关翎,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,762評論 2 345

推薦閱讀更多精彩內(nèi)容

  • 第一部分 來看一下線程池的框架圖笤休,如下: 1尖飞、Executor任務(wù)提交接口與Executors工具類 Execut...
    壓抑的內(nèi)心閱讀 4,247評論 1 24
  • 進(jìn)程和線程 進(jìn)程 所有運(yùn)行中的任務(wù)通常對應(yīng)一個(gè)進(jìn)程,當(dāng)一個(gè)程序進(jìn)入內(nèi)存運(yùn)行時(shí),即變成一個(gè)進(jìn)程.進(jìn)程是處于運(yùn)行過程中...
    勝浩_ae28閱讀 5,085評論 0 23
  • 【JAVA 線程】 線程 進(jìn)程:是一個(gè)正在執(zhí)行中的程序。每一個(gè)進(jìn)程執(zhí)行都有一個(gè)執(zhí)行順序。該順序是一個(gè)執(zhí)行路徑政基,或者...
    Rtia閱讀 2,758評論 2 20
  • Java-Review-Note——4.多線程 標(biāo)簽: JavaStudy PS:本來是分開三篇的贞铣,后來想想還是整...
    coder_pig閱讀 1,629評論 2 17
  • 原文出處http://cmsblogs.com/ 『chenssy』 作為Executor框架中最核心的類,Thr...
    踩在浪花上看浪閱讀 1,221評論 0 4