Comments (10)
非常感谢回复!昨天晚上通过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.
请提供一个 极简、可运行、复现问题的 代码Demo工程。 @guofeiwu
推荐提供成一个单独的工程(Github repo)。这样可以:
- 方便大家能排查分析(只提供片段代码、运行结果,排查信息不足)
- 方便分离不相关的业务实现内容,以及排除可能的业务使用问题
如使用配置问题、其它业务代码的意外影响
from transmittable-thread-local.
@oldratlee 你好!
我今天写了一个agent,自己写了新demo中使用TTL,发现是可以增强的,应该是公司的agent哪里有问题,没增强成功,下周我在公司,替换一个agent试一试,谢谢!
from transmittable-thread-local.
from transmittable-thread-local.
这种方式子线程也无法获取到父线程的值,是我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.
等我周末用电脑整理一下,然后在编辑一次,给大家提供思路;
期待整理分享 👍 ❤️ @guofeiwu
from transmittable-thread-local.
请求到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.
请问一下nioEventLoopGroup线程中的值可以透传到ThreadPoolExecutor的线程池中的线程里吗?
这个是TTL
的使用;具体我没有了解研究。@guofeiwu
from transmittable-thread-local.
遇到一个比较奇怪的问题:
// 简写,希望能看明白,手机操作,还望见谅,谢谢
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 你好!
我今天写了一个agent,自己写了新demo中使用TTL,发现是可以增强的,应该是公司的agent哪里有问题,没增强成功,下周我在公司,替换一个agent试一试,谢谢!
好的, issue 先 close 了。
from transmittable-thread-local.
Related Issues (20)
- 如何在ttl里面使用BinaryOperator HOT 1
- 使用Java agent不生效,通过arthas jad看对应的类,均已被transform,但是trace不到TtlRunnable和TransmittableThreadLocal的执行记录 HOT 6
- 引入byte-buddy依赖导致Ttl增强失败 HOT 1
- TTL-agent修饰后的ScheduledThreadPoolExecutor的调度任务在取消时,无法从workQueue中清除 HOT 2
- java.lang.IllegalStateException: TTL logger implementation type is already set! type = 0 HOT 2
- java.lang.IllegalStateException: TTL logger implementation type is NOT set! HOT 1
- 2.14.3版本在JDK 21中遇到了类转换异常问题,TTL是否支持JDK 21? HOT 13
- agent 2.14.3 JDK17 报错 HOT 5
- -javaagent:D:\jar\transmittable-thread-local-2.14.0.jar 必须使用带版本号的名称,去除版本号会报错 HOT 1
- k8s环境下CPU调整>2数量后线程上下文传递失效 HOT 1
- 官方maven仓库的版本没有同步? HOT 2
- ListenableFuture添加了监听回调,回调线程获取不到正确的值? HOT 3
- 配合线程池使用时,remove了之后,下一个任务还是能拿到上一个任务设置的值 HOT 1
- 线上运行开始父子线程可以传递threadlocal变量,运行一段时间失效 HOT 1
- 使用jrebel -javaagent方式启动,在stream().parallel()无法正确获取内容
- jdk并发流parallelStream支持这种改造吗 HOT 1
- 在Java21的虚拟线程中不使用`TTL`会有问题吗? HOT 1
- TtlRunnable是否可以支持PriorityQueue和DelayQueue HOT 2
- 从哪里可以看到每个版本迭代哪些内容,或者修复了哪些bug HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from transmittable-thread-local.