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

How to obtain main thread information in HintManager thread pool scenario #31042

Open
penweizgx opened this issue Apr 28, 2024 · 5 comments
Open

Comments

@penweizgx
Copy link

In a multi-tenant project implemented using Spring Boot, JPA, and ShardingSphere JDBC 5.2.1, I need to access the corresponding table based on the requested tenant ID. For instance, when user 'a' under a certain system tenant accesses student information, the SQL should be routed to the table t_student_{tenant_id}. Currently, this works as expected when called from the main thread. However, when invoked via asynchronous threads or parallel calls using Stream (with ForkJoinPool), since HintManager relies on ThreadLocal for context propagation and fails to inherit the parent thread's information, what approaches can be taken to achieve this goal?

@strongduanmu
Copy link
Member

Can you try the new 5.5.0 version? This version may solve this problem.

@strongduanmu
Copy link
Member

Since this issue has long time no response, I will close it.

@penweizgx
Copy link
Author

I looked at the new implementation and it doesn't seem to have changed much

@strongduanmu strongduanmu reopened this May 11, 2024
@strongduanmu
Copy link
Member

I looked at the new implementation and it doesn't seem to have changed much

Hi @penweizgx I checked the code again and there is indeed no modification here. I think we can try to use TransmittableThreadLocal to solve this problem.

@penweizgx
Copy link
Author

yes

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

No branches or pull requests

2 participants