dromara / dynamic-tp

🔥🔥🔥轻量级动态线程池,内置监控告警功能,集成三方中间件线程池管理,基于主流配置中心(已支持Nacos、Apollo,Zookeeper、Consul、Etcd,可通过SPI自定义实现)。Lightweight dynamic threadpool, with monitoring and alarming functions, base on popular config centers (already support Nacos、Apollo、Zookeeper、Consul, can be customized through SPI).
https://dynamictp.cn
Apache License 2.0
3.77k stars 763 forks source link

ScheduledDtpExecutor不支持TaskWrapper #431

Closed nathanchoui closed 2 months ago

nathanchoui commented 3 months ago

背景

1.1.8-beta版本下

问题描述

在使用ScheduledDtpExecutor时,指定了taskWrapperNames: [ "custom" ]。无论执行ScheduledDtpExecutor的哪个方法都不会执行指定的TaskWrapper。 经过Debug发现,调用路径ScheduledDtpExecutor#execute(Runnable command) --> ScheduledDtpExecutor#schedule(Runnable command, long delay, TimeUnit unit) --> ScheduledThreadPoolExecutor#schedule(Runnable command, long delay, TimeUnit unit) 。 虽然在ScheduledThreadPoolExecutorProxy实现了execute ScheduledThreadPoolExecutorProxy

    @Override
    public void execute(Runnable command) {
        command = getEnhancedTask(command);
        AwareManager.execute(this, command);
        super.execute(command);
    }

但是在ScheduledDtpExecutor中无论是execute还是schedule方法,都调用的是proxy的schedule方法,该proxy中execute方法根本不会被执行。

这个是设计初衷是什么? 我的理解,executorAware这些扩展在定时任务时失去了意义,可以不支持,但是TaskWrapper是可以实现的,也比较容易实现。 以后版本有支持计划吗?

KamToHung commented 3 months ago

背景

1.1.8-beta版本下

问题描述

在使用ScheduledDtpExecutor时,指定了taskWrapperNames: [ "custom" ]。无论执行ScheduledDtpExecutor的哪个方法都不会执行指定的TaskWrapper。 经过Debug发现,调用路径ScheduledDtpExecutor#execute(Runnable command) --> ScheduledDtpExecutor#schedule(Runnable command, long delay, TimeUnit unit) --> ScheduledThreadPoolExecutor#schedule(Runnable command, long delay, TimeUnit unit) 。 虽然在ScheduledThreadPoolExecutorProxy实现了execute ScheduledThreadPoolExecutorProxy

    @Override
    public void execute(Runnable command) {
        command = getEnhancedTask(command);
        AwareManager.execute(this, command);
        super.execute(command);
    }

但是在ScheduledDtpExecutor中无论是execute还是schedule方法,都调用的是proxy的schedule方法,该proxy中execute方法根本不会被执行。

这个是设计初衷是什么? 我的理解,executorAware这些扩展在定时任务时失去了意义,可以不支持,但是TaskWrapper是可以实现的,也比较容易实现。 以后版本有支持计划吗?

之前delegate = new ScheduledThreadPoolExecutor(corePoolSize, threadFactory, handler),优化为是用代理但是调用方法没修改,属于bug,感谢指出

nathanchoui commented 3 months ago

背景

1.1.8-beta版本下

问题描述

在使用ScheduledDtpExecutor时,指定了taskWrapperNames: [ "custom" ]。无论执行ScheduledDtpExecutor的哪个方法都不会执行指定的TaskWrapper。 经过Debug发现,调用路径ScheduledDtpExecutor#execute(Runnable command) --> ScheduledDtpExecutor#schedule(Runnable command, long delay, TimeUnit unit) --> ScheduledThreadPoolExecutor#schedule(Runnable command, long delay, TimeUnit unit) 。 虽然在ScheduledThreadPoolExecutorProxy实现了execute ScheduledThreadPoolExecutorProxy

    @Override
    public void execute(Runnable command) {
        command = getEnhancedTask(command);
        AwareManager.execute(this, command);
        super.execute(command);
    }

但是在ScheduledDtpExecutor中无论是execute还是schedule方法,都调用的是proxy的schedule方法,该proxy中execute方法根本不会被执行。 这个是设计初衷是什么? 我的理解,executorAware这些扩展在定时任务时失去了意义,可以不支持,但是TaskWrapper是可以实现的,也比较容易实现。 以后版本有支持计划吗?

之前delegate = new ScheduledThreadPoolExecutor(corePoolSize, threadFactory, handler),优化为是用代理但是调用方法没修改,属于bug,感谢指出

看源码,设计之初就只支持execute方法,schedule相关方法是否也能支持。并且是否可以提供Callable相关包装的扩展接口。