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

跨线程问题 #29

Open
steverpm890 opened this issue Oct 16, 2024 · 2 comments
Open

跨线程问题 #29

steverpm890 opened this issue Oct 16, 2024 · 2 comments

Comments

@steverpm890
Copy link

在非Undertow线程,注入不成功。
调试了,发现,是在getContext,这里获取失败

@pen4uin
Copy link
Owner

pen4uin commented Oct 17, 2024

你贴一下 undertow 版本 和 jdk 版本吧

@steverpm890
Copy link
Author

starting server: Undertow - 2.2.10.Final
jdk11
我调了下,发现不是版本的问题
Object requestContext = invokeMethod(threads[i].getContextClassLoader().loadClass("io.undertow.servlet.handlers.ServletRequestContext"), "current");
Object servletContext = invokeMethod(requestContext, "getCurrentServletContext");

这2句,在非undertow线程执行,是有问题,如果当前,没有请求,是获取不到servletContext的
因为在io.undertow.servlet.handlers.ServletRequestContext
setCurrentRequestContext,一个request完成后,这里会被置空,也就是ThreadLocal,会被清掉

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

2 participants