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

疑问:客户端任务执行的触发没有用线程池 #3546

Open
LeYunone opened this issue Sep 18, 2024 · 0 comments
Open

疑问:客户端任务执行的触发没有用线程池 #3546

LeYunone opened this issue Sep 18, 2024 · 0 comments

Comments

@LeYunone
Copy link

LeYunone commented Sep 18, 2024

版本

所有版本

问题

在客户端触发定时任务的动作里,见 JobThread 类;

if (triggerParam.getExecutorTimeout() > 0) {
    // limit timeout
    Thread futureThread = null;
    try {
        FutureTask<Boolean> futureTask = new FutureTask<Boolean>(new Callable<Boolean>() {
            @Override
            public Boolean call() throws Exception {

                // init job context
                XxlJobContext.setXxlJobContext(xxlJobContext);

            handler.execute();
            return true;
            }
        });
        futureThread = new Thread(futureTask);
        futureThread.start();

        Boolean tempResult = futureTask.get(triggerParam.getExecutorTimeout(), TimeUnit.SECONDS);
	}
//.....

采用了创建线程为载体,实现任务超时的回调函数;

疑问

因为需要考虑任务上下文 XxlJobContext ,父线程和子线程需要共享一个 ThreadLocal ,所以使用线程+InheritableThreadLocal 的组合(上述代码)可以理解;
不过目前存有大量任务,都设有超时时间,并且存在会同时频繁执行的情况;
这样一来以上代码对原本平稳运行的系统会带来不小的隐患。
所以未来是否会考虑使用线程池+TransmittableThreadLocal 的模式取代上述旧的执行逻辑 🤝

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant