arthas 监控线程池相关对象

具体代码,需要设置类的变量,不能设置方法的局部变量

package com.xxx.vman.service;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.Semaphore;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Slf4j
public class Test2 {

    private static Semaphore semaphore = new Semaphore(3);
    private static ThreadPoolExecutor executorService = new ThreadPoolExecutor(10,50,60, TimeUnit.SECONDS,new LinkedBlockingQueue<>(200));

    @SneakyThrows
    static void exec(){
        try {
            semaphore.acquire();
            log.info("执行exec方法" + Thread.currentThread().getName());
            Thread.sleep(310);
        } finally {
            semaphore.release();
        }
    }

    @Test
    @SneakyThrows
    public void test(){
        for (;;){
            Thread.sleep(100);
            executorService.execute(() -> exec());
        }
    }

}

arthas监控查看executorService属性命令

ognl -x 3 '@com.xxx.vman.service.Test2@executorService'

查看Test2类对象的属性命令

 vmtool -x 3 --action getInstances --className com.xxx.vman.service.Test2  --express 'instances[0]'

你可能感兴趣的:(java,数据库,开发语言)