Skywalking: [Agent] Plugin for Spring ThreadPoolTaskExecutor

Created on 27 Sep 2017  ·  10Comments  ·  Source: apache/skywalking

Please answer these questions before submitting your issue.
我们的程序需要是用线程池来发送kafka消息。能看到线程的情况吗?

question

All 10 comments

线程池默认是不支持的,线程问题需要单独讨论。能提供一下你们线程使用的示例代码么?

就像这样 ThreadPoolTaskExecutor 用一个固定的线程池。

//异步执行
        Long finalRecordCount = recordCount;

   threadPool.execute(() -> {
            try {
                //要发送的json
                TemplateMsg templateMsg = new TemplateMsg();
                templateMsg.setIsLast(false);
                templateMsg.setAppId(request.getAppId());
                templateMsg.setTemplateId(task.getId());
                logger.info("发送模板消息,:Condition{}", request);
                zbusProducer.sendTemplateMsg(templateMsg);
             // *********省略业务代码**********/
            } catch (Exception e) {
                logger.error("发送模板消息错误,:e{}", e);
            }
        });

好吧。谢谢回复。

cc @ascrutae . From the sample codes, I think we have a chance to provide a plugin for this thread pool, which intercept the the parameter of execute(), and use the snapshot and override the run() to accomplish the propagation across thread. Also can avoid to dev a plugin for all runnable implementations, which is insane, and not realistic.

@wtj199101 请提供一下所使用的类库,以及对应的版本,谢谢。

@wtj199101 ThreadPoolTaskExecutor我印象中,应该是Spring的一部分。

yes。使用了spring boot 1.4.3.RELEASE jdk1.8 @EnableAsync 开启异步支持后直接使用。这种线程池里面的线程执行时间和参数能通过agent方式得到吗?

@wtj199101 可以的,可以通过拦截你传入的Runnable接口的方法得到执行时间,和执行链路情况。但是参数需要你通过代码和agent交互才可以。我们需要提供一个新的plugin,才能支持你这种写法。

@carlvine500 Do you have interested to provide this plugin?

@wu-sheng I think it's already supported , @wtj199101 follow my example:

        ExecutorService threadPool = Executors.newFixedThreadPool(1);

        // your code
        threadPool.execute(() -> {
            try {
                //
            } catch (Exception e) {
                //
            }
        });

        // your code with trace across thread
        threadPool.execute(RunnableWrapper.of(() -> {
            try {
                //
            } catch (Exception e) {
                //
            }
        }));
Was this page helpful?
0 / 5 - 0 ratings

Related issues

yang-xiaodong picture yang-xiaodong  ·  4Comments

wu-sheng picture wu-sheng  ·  3Comments

EvanLjp picture EvanLjp  ·  5Comments

valyala picture valyala  ·  3Comments

Icefoxes picture Icefoxes  ·  3Comments