Giter Club home page Giter Club logo

Comments (10)

guofeiwu avatar guofeiwu commented on June 18, 2024 3

非常感谢回复!昨天晚上通过debug的方式问题已经找到了,我没有复写以下两个方法

public class MyThreadPoolExecutor extends ThreadPoolExecutor


    @Override
    protected void beforeExecute(Thread t, Runnable r) {
        super.beforeExecute(t, r);
    }

    @Override
    protected void afterExecute(Runnable r, Throwable t) {
        super.afterExecute(r, t);
    }

不方便用电脑回复,手机回复格式有点乱,等我周末用电脑整理一下,然后在编辑一次,给大家提供思路;

from transmittable-thread-local.

oldratlee avatar oldratlee commented on June 18, 2024 1

请提供一个 极简、可运行、复现问题的 代码Demo工程。 @guofeiwu

推荐提供成一个单独的工程(Github repo)。这样可以:

  • 方便大家能排查分析(只提供片段代码、运行结果,排查信息不足)
  • 方便分离不相关的业务实现内容,以及排除可能的业务使用问题
    如使用配置问题、其它业务代码的意外影响

from transmittable-thread-local.

guofeiwu avatar guofeiwu commented on June 18, 2024 1

@oldratlee 你好!

我今天写了一个agent,自己写了新demo中使用TTL,发现是可以增强的,应该是公司的agent哪里有问题,没增强成功,下周我在公司,替换一个agent试一试,谢谢!

from transmittable-thread-local.

guofeiwu avatar guofeiwu commented on June 18, 2024

@abcdea @driventokill

from transmittable-thread-local.

guofeiwu avatar guofeiwu commented on June 18, 2024

这种方式子线程也无法获取到父线程的值,是我TTL agent的方式增强失败了吗?

threadPoolExecutor.execute(new MyRun());

public static class MyRun implements Runnable {
    @Override
    public void run() {
        log.info(new XXLog()
                .op("TestTraceController")
                .kv("threadname", Thread.currentThread().getName())
                .kv("testtrace","getRpcExecutor线程池执行")
                .toString());
    }
}

谢谢!期待回复一下!首次使用TTL

from transmittable-thread-local.

oldratlee avatar oldratlee commented on June 18, 2024

等我周末用电脑整理一下,然后在编辑一次,给大家提供思路;

期待整理分享 👍 ❤️ @guofeiwu

from transmittable-thread-local.

guofeiwu avatar guofeiwu commented on June 18, 2024

请求到nioEventLoopGroup-8-1线程中执行MyThreadPoolExecutor.execute(new MyRun());

public static class MyRun implements Runnable {

		@Override
		public void run() {
			log.info(new XXLog()
					.op("TestTraceController")
					.kv("threadname", Thread.currentThread().getName())
					.kv("testtrace","getRpcExecutor线程池执行")
					.toString());
		}
	}

在MyRun线程中,获取不到nioEventLoopGroup-8-1线程中设置的值,nioEventLoopGroup-8-1线程中执行MyThreadPoolExecutor的已经被agent增强过,debug看是增强的。

请问一下nioEventLoopGroup线程中的值可以透传到ThreadPoolExecutor的线程池中的线程里吗?

from transmittable-thread-local.

oldratlee avatar oldratlee commented on June 18, 2024

请问一下nioEventLoopGroup线程中的值可以透传到ThreadPoolExecutor的线程池中的线程里吗?

这个是TTL的使用;具体我没有了解研究。@guofeiwu

from transmittable-thread-local.

guofeiwu avatar guofeiwu commented on June 18, 2024

遇到一个比较奇怪的问题:
// 简写,希望能看明白,手机操作,还望见谅,谢谢

Main {

	// 在主程序中
	@Autowired
	private MyThreadPoolExecutor myThreadPoolExecutor ;
	
	
    myThreadPoolExecutor.execute(new MyRun());

	// 请求第一次进来,main线程的traceId = 3c562f9ae4c5593e
	// myThreadPoolExecutor.execute(new MyRun()) 打印的traceId = 3c562f9ae4c5593e


	// 同样再发起一次请求
	// 请求第二次进来,main线程的traceId = ea1b657224e7d3be
	// 第二次myThreadPoolExecutor.execute(new MyRun()) 打印的traceId = 3c562f9ae4c5593e
    
    // 反复操作多次任然是如此

	// 使用myThreadPoolExecutor提交的任务的traceId一旦有值了,就不在变化了
    // 我是通过TTL agent方式启动的,公司代码,暂时无法提供可运行的demo程序
    // debug启动的时候我断点是能够进入TtlExecutorTransformlet.java源代码的78行
			logger.info("Transforming class " + classInfo.getClassName());// 78
            final boolean modified = updateBeforeAndAfterExecuteMethodOfExecutorSubclass(clazz);//80 这个返回的是true
            if (modified) classInfo.setModified();//81
	// 这个modified返回true是不是表示 增强成功呢?

   // 若是没有增强成功?请问一下,为什么线程池中的任务能够拿到父线程的traceId呢?且怎么样判断怎么样才算是增强成功呢? 
   // 还望提供一点思路,谢谢!!!
}


public class MyThreadPoolExecutor extends ThreadPoolExecutor {
    public MyThreadPoolExecutor(int corePoolSize,
                                 int maximumPoolSize,
                                 long keepAliveTime,
                                 int queueCapacity,
                                 String threadNamePrefix) {
        super(corePoolSize,
        maximumPoolSize,
        keepAliveTime,
        TimeUnit.SECONDS,
        new LinkedBlockingQueue<>(queueCapacity),
        new NamedThreadFactory(threadNamePrefix),
        new ThreadPoolRejectPolicy());
    }
	/**
	 * 复写该方法为了ttl agent能够增强,请勿删除
	 *
	 * @param t
	 * @param r
	 */
	@Override
	protected void beforeExecute(Thread t, Runnable r) {
		super.beforeExecute(t, r);
	}

	/**
	 * 复写该方法为了ttl agent能够增强,请勿删除
	 *
	 * @param t
	 * @param r
	 */
	@Override
	protected void afterExecute(Runnable r, Throwable t) {
		super.afterExecute(r, t);
	}
}


public static class MyRun implements Runnable {
		@Override
		public void run() {
			log.info(new XXLog()
					.op("TestTraceController")
					.kv("threadname", Thread.currentThread().getName())
					.kv("testtrace","MyRun执行")
					.toString());
		}
}

from transmittable-thread-local.

oldratlee avatar oldratlee commented on June 18, 2024

@oldratlee 你好!

我今天写了一个agent,自己写了新demo中使用TTL,发现是可以增强的,应该是公司的agent哪里有问题,没增强成功,下周我在公司,替换一个agent试一试,谢谢!

好的, issue 先 close 了。

from transmittable-thread-local.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.