The thread pool that comes with jdk that will be touched in concurrency

Introduction to the general class of JDK's own thread pool:
1. The new FixedThreadPool creates a thread pool that specifies the number of worker threads. Whenever a task is submitted, a worker thread is created. If the number of worker threads reaches the initial maximum number of the thread pool, the submitted task is stored in the pool queue.

2. new CachedThreadPool creates a cacheable thread pool. The characteristics of this type of thread pool are:
    1). There is almost no limit to the number of worker threads created (in fact, there is also a limit, the number is Interger. MAX_VALUE), so that threads can be flexibly added to the thread pool.
    2). If the task is not submitted to the thread pool for a long time, that is, if the worker thread is idle for the specified time (1 minute by default), the worker thread will be automatically terminated. After termination, if you submit a new task, the thread pool recreates a worker thread.

3. new SingleThreadExecutor creates a single-threaded Executor, that is, only creates a unique worker thread to execute tasks. If this thread ends abnormally, another one will replace it to ensure sequential execution (I think this is its characteristic) . The biggest feature of a single worker thread is that it guarantees that tasks are executed sequentially, and that no more than one thread is active at any given time.

4. The new ScheduleThreadPool creates a fixed-length thread pool, and supports timed and periodic task execution, similar to Timer.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326677859&siteId=291194637