thread50 - SinglePool

本文通过具体示例展示了如何创建并使用单线程池。在Java中,利用`Executors.newSingleThreadExecutor()`可以轻松创建单线程池,确保任务按顺序执行。文章还提供了线程池状态的变化过程及线程的运行情况。
package com.neutron.t23;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * 线程池
 *    1.固定个数的线程池
 *    2.缓存线程池,开始线程数0
 *         如果需要线程,当前线程池没有,那么创建线程池
 *         如果需要线程,线程池中有没有使用的线程,那么使用已经存在的线程
 *         如果线程池中线程超过60秒(默认)没有使用,那么该线程停止
 *    3.只有1个线程的线程池
 *         保证线程执行的先后顺序
 */
public class T239SinglePool {

    /*
    T1:java.util.concurrent.ThreadPoolExecutor@2503dbd3
    [Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]
    T2:java.util.concurrent.ThreadPoolExecutor@2503dbd3
    [Running, pool size = 2, active threads = 2, queued tasks = 0, completed tasks = 0]
    pool-1-thread-1
    pool-1-thread-2
    T3:java.util.concurrent.ThreadPoolExecutor@2503dbd3
    [Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 2]
     */
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        // 创建个数为1的线程池
        ExecutorService service = Executors.newSingleThreadExecutor();

        for (int i = 0; i < 2; i++) {
            final int j = i;
            service.execute(() -> {
                try {
                    TimeUnit.MILLISECONDS.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(j + ":" + Thread.currentThread().getName());
            });
        }
        service.shutdown();
    }

}

mysql数据库中,如何分析SHOW ENGINE INNODB STATUS命令查询的status状态内容?以下是status具体状态内容:---TRANSACTION 421404629562648, not started 0 lock struct(s), heap size 1128, 0 row lock(s) ---TRANSACTION 421404629563624, not started 0 lock struct(s), heap size 1128, 0 row lock(s) ---TRANSACTION 421404629564600, not started 0 lock struct(s), heap size 1128, 0 row lock(s) ---TRANSACTION 421404629565576, not started 0 lock struct(s), heap size 1128, 0 row lock(s) ---TRANSACTION 421404629566552, not started 0 lock struct(s), heap size 1128, 0 row lock(s) ---TRANSACTION 421404629567528, not started 0 lock struct(s), heap size 1128, 0 row lock(s) ---TRANSACTION 421404629568504, not started 0 lock struct(s), heap size 1128, 0 row lock(s) ---TRANSACTION 421404629569480, not started 0 lock struct(s), heap size 1128, 0 row lock(s) ---TRANSACTION 421404629570456, not started 0 lock struct(s), heap size 1128, 0 row lock(s) ---TRANSACTION 421404629571432, not started 0 lock struct(s), heap size 1128, 0 row lock(s) ---TRANSACTION 421404629572408, not started 0 lock struct(s), heap size 1128, 0 row lock(s) ---TRANSACTION 421404629573384, not started 0 lock struct(s), heap size 1128, 0 row lock(s) ---TRANSACTION 421404629574360, not started 0 lock struct(s), heap size 1128, 0 row lock(s) ---TRANSACTION 421404629576312, not started 0 lock struct(s), heap size 1128, 0 row lock(s) ---TRANSACTION 421404629577288, not started 0 lock struct(s), heap size 1128, 0 row lock(s) -------- FILE I/O -------- I/O thread 0 state: waiting for completed aio requests (insert buffer thread) I/O thread 1 state: waiting for completed aio requests (log thread) I/O thread 2 state: waiting for completed aio requests (read thread) I/O thread 3 state: waiting for completed aio requests (read thread) I/O thread 4 state: waiting for completed aio requests (read thread) I/O thread 5 state: waiting for completed aio requests (read thread) I/O thread 6 state: waiting for completed aio requests (write thread) I/O thread 7 state: waiting for completed aio requests (write thread) I/O thread 8 state: waiting for completed aio requests (write thread) I/O thread 9 state: waiting for completed aio requests (write thread) Pending normal aio reads: [0, 0, 0, 0] , aio writes: [0, 0, 0, 0] , ibuf aio reads:, log i/o's: Pending flushes (fsync) log: 0; buffer pool: 471742 156526629 OS file reads, 3674182546 OS file writes, 1759120682 OS fsyncs 10.44 reads/s, 16384 avg bytes/read, 166.03 writes/s, 84.62 fsyncs/s ------------------------------------- INSERT BUFFER AND ADAPTIVE HASH INDEX ------------------------------------- Ibuf: size 1, free list len 810, seg size 812, 47095351 merges merged operations: insert 47065383, delete mark 19475262, delete 130 discarded operations: insert 0, delete mark 0, delete 0 Hash table size 3187567, node heap has 0 buffer(s) Hash table size 3187567, node heap has 0 buffer(s) Hash table size 3187567, node heap has 0 buffer(s) Hash table size 3187567, node heap has 0 buffer(s) Hash table size 3187567, node heap has 0 buffer(s) Hash table size 3187567, node heap has 0 buffer(s) Hash table size 3187567, node heap has 0 buffer(s) Hash table size 3187567, node heap has 0 buffer(s) 0.00 hash searches/s, 814.73 non-hash searches/s --- LOG --- Log sequence number 3330574935903 Log buffer assigned up to 3330574935903 Log buffer completed up to 3330574935903 Log written up to 3330574935652 Log flushed up to 3330574935652 Added dirty pages up to 3330574935903 Pages flushed up to 3330415619252 Last checkpoint at 3330415602572 Log minimum file id is 11990 Log maximum file id is 12015 2617778760 log i/o's done, 190.33 log i/o's/second ---------------------- BUFFER POOL AND MEMORY ---------------------- Total large memory allocated 0 Dictionary memory allocated 11696030 Buffer pool size 786363 Free buffers 8185 Database pages 778178 Old database pages 287097 Modified db pages 88854 Pending reads 0 Pending writes: LRU 0, flush list 0, single page 0 Pages made young 183887271, not young 394584552 15.26 youngs/s, 8.03 non-youngs/s Pages read 156528367, created 38875034, written 747882266 10.44 reads/s, 1.34 creates/s, 6.43 writes/s Buffer pool hit rate 998 / 1000, young-making rate 3 / 1000 not 2 / 1000 Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s LRU len: 778178, unzip_LRU len: 0 I/O sum[5264]:cur[16], unzip sum[0]:cur[0] ---------------------- INDIVIDUAL BUFFER POOL INFO ---------------------- ---BUFFER POOL 0 Buffer pool size 98296 Free buffers 1024 Database pages 97272 Old database pages 35887 Modified db pages 11270 Pending reads 0 Pending writes: LRU 0, flush list 0, single page 0 Pages made young 15652571, not young 49850012 1.34 youngs/s, 0.80 non-youngs/s Pages read 20104859, created 3002366, written 92590187 0.80 reads/s, 0.00 creates/s, 0.80 writes/s Buffer pool hit rate 999 / 1000, young-making rate 3 / 1000 not 1 / 1000 Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahea
最新发布
01-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值