Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

好像不支持 TtlExecutors #425

Open
shanhm1991 opened this issue Jun 13, 2024 · 6 comments
Open

好像不支持 TtlExecutors #425

shanhm1991 opened this issue Jun 13, 2024 · 6 comments
Labels
feature question Further information is requested

Comments

@shanhm1991
Copy link

首先感谢您使用 DynamicTp,如果对项目有好的想法建议,请按照下述模板提议讨论,建议使用 Markdown 语法

解析DynamicTp时对bean这里做过滤,能不能直接支持Executor,不然使用 TtlExecutors.getTtlExecutor(taskExecutor); 装饰的线程池就被忽略了

@Override
    public Object postProcessAfterInitialization(@NonNull Object bean, @NonNull String beanName) throws BeansException {
        if (!(bean instanceof ThreadPoolExecutor) && !(bean instanceof ThreadPoolTaskExecutor)) {
            return bean;
        }
        if (bean instanceof DtpExecutor) {
            return registerAndReturnDtp(bean);
        }
        // register juc ThreadPoolExecutor or ThreadPoolTaskExecutor
        return registerAndReturnCommon(bean, beanName);
    }
@KamToHung
Copy link
Collaborator

首先感谢您使用 DynamicTp,如果对项目有好的想法建议,请按照下述模板提议讨论,建议使用 Markdown 语法

解析DynamicTp时对bean这里做过滤,能不能直接支持Executor,不然使用 TtlExecutors.getTtlExecutor(taskExecutor); 装饰的线程池就被忽略了

@Override
    public Object postProcessAfterInitialization(@NonNull Object bean, @NonNull String beanName) throws BeansException {
        if (!(bean instanceof ThreadPoolExecutor) && !(bean instanceof ThreadPoolTaskExecutor)) {
            return bean;
        }
        if (bean instanceof DtpExecutor) {
            return registerAndReturnDtp(bean);
        }
        // register juc ThreadPoolExecutor or ThreadPoolTaskExecutor
        return registerAndReturnCommon(bean, beanName);
    }

如果想使用ttl,可以通过dynamic-top的包装器包装,支持TtlTaskWrapper

@shanhm1991
Copy link
Author

感谢回复,这个问题暂时规避了,改成了只包装里面的Runnable

public void execute(Runnable task) {
        super.execute(TtlRunnable.get(task, false, true));
}

另外感觉有个问题,在DtpRunnable执行run时是不是应该将跟踪id值设置一下 MDC.put(TRACE_ID, traceId);

这里加了一个自己需要的跟踪id,不然任务线程打印日志中获取不到

image

@KamToHung
Copy link
Collaborator

感谢回复,这个问题暂时规避了,改成了只包装里面的Runnable

public void execute(Runnable task) {
        super.execute(TtlRunnable.get(task, false, true));
}

另外感觉有个问题,在DtpRunnable执行run时是不是应该将跟踪id值设置一下 MDC.put(TRACE_ID, traceId);

这里加了一个自己需要的跟踪id,不然任务线程打印日志中获取不到

image

MDC也有个包装器,MdcTaskWrapper可以使用,MDC.put应该属于业务处理,可以在execute之前put

@shanhm1991
Copy link
Author

1718347569883

这里是不是返回proxy更好(直接返回bean,虽然可以注入ThreadPoolTaskExecutor,但已经是一个被Terminated的实例)

本地话将返回改成了proxy,注入类型换成ThreadPoolExecutor,简单规避掉了问题

@yanhom1314
Copy link
Collaborator

yanhom1314 commented Jun 14, 2024

1718347569883

这里是不是返回proxy更好(直接返回bean,虽然可以注入ThreadPoolTaskExecutor,但已经是一个被Terminated的实例)

本地话将返回改成了proxy,注入类型换成ThreadPoolExecutor,简单规避掉了问题

Terminated 的是bean里面的threadPoolExecutor,返回之前已经通过反射将proxy设置到bean里了,所以返回bean没问题。而且proxy是个ThreadPoolExecutor,直接返回,原始类型是ThreadPoolTaskExecutor,会报类型转换错误

@yanhom1314 yanhom1314 added the question Further information is requested label Jun 14, 2024
@shanhm1991
Copy link
Author

https://dynamictp.cn/guide/use/wrapper.html#%E4%BB%BB%E5%8A%A1%E5%8C%85%E8%A3%85%E5%99%A8

能不能不需要通过配置文件来指定包装(很麻烦),直接在@DynamicTp中附近一些属性,来让别人说明要指定的包装类型

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants